]> Cypherpunks repositories - gostls13.git/commitdiff
misc: remove use of relative directories in overlayDir functions
authorBryan C. Mills <bcmills@google.com>
Fri, 22 Nov 2019 21:06:11 +0000 (16:06 -0500)
committerBryan C. Mills <bcmills@google.com>
Mon, 25 Nov 2019 16:26:15 +0000 (16:26 +0000)
It turns out that the relative-path support never worked in the first
place.

It had been masked by the fact that we ~never invoke overlayDir with
an absolute path, which caused filepath.Rel to always return an error,
and overlayDir to always fall back to absolute paths.

Since the absolute paths seem to be working fine (and are simpler),
let's stick with those. As far as I can recall, the relative paths
were only a space optimization anyway.

Updates #28387
Updates #30316

Change-Id: Ie8cd28f3c41ca6497ace2799f4193d7f5dde7a37
Reviewed-on: https://go-review.googlesource.com/c/go/+/208481
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
misc/cgo/life/overlaydir_test.go
misc/cgo/stdio/overlaydir_test.go
misc/cgo/test/overlaydir_test.go
misc/cgo/testcarchive/overlaydir_test.go
misc/cgo/testcshared/overlaydir_test.go
misc/cgo/testplugin/overlaydir_test.go
misc/cgo/testshared/overlaydir_test.go
misc/cgo/testso/overlaydir_test.go
misc/cgo/testsovar/overlaydir_test.go
misc/reboot/overlaydir_test.go

index a25b125c7c38396c8970a885450d6daac50665d1..034c836248db40a15d09492013839ecf521cce1f 100644 (file)
@@ -21,12 +21,9 @@ func overlayDir(dstRoot, srcRoot string) error {
                return err
        }
 
-       symBase, err := filepath.Rel(srcRoot, dstRoot)
+       srcRoot, err := filepath.Abs(srcRoot)
        if err != nil {
-               symBase, err = filepath.Abs(srcRoot)
-               if err != nil {
-                       return err
-               }
+               return err
        }
 
        return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
@@ -52,11 +49,11 @@ func overlayDir(dstRoot, srcRoot string) error {
                // Always copy directories (don't symlink them).
                // If we add a file in the overlay, we don't want to add it in the original.
                if info.IsDir() {
-                       return os.Mkdir(dstPath, perm|0200)
+                       return os.MkdirAll(dstPath, perm|0200)
                }
 
                // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
+               if err := os.Symlink(srcPath, dstPath); err == nil {
                        return nil
                }
 
index 5d6858f9605109e72c7bd1bba442ee43869d9636..027ebf17c3f25db4c415c03b3759bd7bf2ef591f 100644 (file)
@@ -21,12 +21,9 @@ func overlayDir(dstRoot, srcRoot string) error {
                return err
        }
 
-       symBase, err := filepath.Rel(srcRoot, dstRoot)
+       srcRoot, err := filepath.Abs(srcRoot)
        if err != nil {
-               symBase, err = filepath.Abs(srcRoot)
-               if err != nil {
-                       return err
-               }
+               return err
        }
 
        return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
@@ -52,11 +49,11 @@ func overlayDir(dstRoot, srcRoot string) error {
                // Always copy directories (don't symlink them).
                // If we add a file in the overlay, we don't want to add it in the original.
                if info.IsDir() {
-                       return os.Mkdir(dstPath, perm|0200)
+                       return os.MkdirAll(dstPath, perm|0200)
                }
 
                // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
+               if err := os.Symlink(srcPath, dstPath); err == nil {
                        return nil
                }
 
index cad9577ca118975f085d6a29bfdf3cb8ca767adf..f651979b657a7073b81fe39dc527569717a74bcf 100644 (file)
@@ -21,12 +21,9 @@ func overlayDir(dstRoot, srcRoot string) error {
                return err
        }
 
-       symBase, err := filepath.Rel(srcRoot, dstRoot)
+       srcRoot, err := filepath.Abs(srcRoot)
        if err != nil {
-               symBase, err = filepath.Abs(srcRoot)
-               if err != nil {
-                       return err
-               }
+               return err
        }
 
        return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
@@ -52,11 +49,11 @@ func overlayDir(dstRoot, srcRoot string) error {
                // Always copy directories (don't symlink them).
                // If we add a file in the overlay, we don't want to add it in the original.
                if info.IsDir() {
-                       return os.Mkdir(dstPath, perm|0200)
+                       return os.MkdirAll(dstPath, perm|0200)
                }
 
                // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
+               if err := os.Symlink(srcPath, dstPath); err == nil {
                        return nil
                }
 
index ee35dd50f7bcb12aae5146d98b812294b899d0f4..67974c5ed8da09851a648f8a60fb59fdfc126d30 100644 (file)
@@ -21,12 +21,9 @@ func overlayDir(dstRoot, srcRoot string) error {
                return err
        }
 
-       symBase, err := filepath.Rel(srcRoot, dstRoot)
+       srcRoot, err := filepath.Abs(srcRoot)
        if err != nil {
-               symBase, err = filepath.Abs(srcRoot)
-               if err != nil {
-                       return err
-               }
+               return err
        }
 
        return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
@@ -52,11 +49,11 @@ func overlayDir(dstRoot, srcRoot string) error {
                // Always copy directories (don't symlink them).
                // If we add a file in the overlay, we don't want to add it in the original.
                if info.IsDir() {
-                       return os.Mkdir(dstPath, perm|0200)
+                       return os.MkdirAll(dstPath, perm|0200)
                }
 
                // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
+               if err := os.Symlink(srcPath, dstPath); err == nil {
                        return nil
                }
 
index 0c23ec0c15a7ad7f301239150786314b35df2213..85d6b44eef5810e8acd8a0877a0b5b086c9a554a 100644 (file)
@@ -21,12 +21,9 @@ func overlayDir(dstRoot, srcRoot string) error {
                return err
        }
 
-       symBase, err := filepath.Rel(srcRoot, dstRoot)
+       srcRoot, err := filepath.Abs(srcRoot)
        if err != nil {
-               symBase, err = filepath.Abs(srcRoot)
-               if err != nil {
-                       return err
-               }
+               return err
        }
 
        return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
@@ -52,11 +49,11 @@ func overlayDir(dstRoot, srcRoot string) error {
                // Always copy directories (don't symlink them).
                // If we add a file in the overlay, we don't want to add it in the original.
                if info.IsDir() {
-                       return os.Mkdir(dstPath, perm|0200)
+                       return os.MkdirAll(dstPath, perm|0200)
                }
 
                // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
+               if err := os.Symlink(srcPath, dstPath); err == nil {
                        return nil
                }
 
index ffb107cf8bdb0deaba5efed584146ceb9f12c268..e2c32d83ce13a947c09b308401b98784343bf822 100644 (file)
@@ -21,12 +21,9 @@ func overlayDir(dstRoot, srcRoot string) error {
                return err
        }
 
-       symBase, err := filepath.Rel(srcRoot, dstRoot)
+       srcRoot, err := filepath.Abs(srcRoot)
        if err != nil {
-               symBase, err = filepath.Abs(srcRoot)
-               if err != nil {
-                       return err
-               }
+               return err
        }
 
        return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
@@ -52,11 +49,11 @@ func overlayDir(dstRoot, srcRoot string) error {
                // Always copy directories (don't symlink them).
                // If we add a file in the overlay, we don't want to add it in the original.
                if info.IsDir() {
-                       return os.Mkdir(dstPath, perm|0200)
+                       return os.MkdirAll(dstPath, perm|0200)
                }
 
                // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
+               if err := os.Symlink(srcPath, dstPath); err == nil {
                        return nil
                }
 
index 3a7c9b04a042f69718df3ef603cc33ac2103e001..eb587a2d44d52c3d3a887cc0be9466f6d03cd9b7 100644 (file)
@@ -21,12 +21,9 @@ func overlayDir(dstRoot, srcRoot string) error {
                return err
        }
 
-       symBase, err := filepath.Rel(srcRoot, dstRoot)
+       srcRoot, err := filepath.Abs(srcRoot)
        if err != nil {
-               symBase, err = filepath.Abs(srcRoot)
-               if err != nil {
-                       return err
-               }
+               return err
        }
 
        return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
@@ -52,11 +49,11 @@ func overlayDir(dstRoot, srcRoot string) error {
                // Always copy directories (don't symlink them).
                // If we add a file in the overlay, we don't want to add it in the original.
                if info.IsDir() {
-                       return os.Mkdir(dstPath, perm|0200)
+                       return os.MkdirAll(dstPath, perm|0200)
                }
 
                // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
+               if err := os.Symlink(srcPath, dstPath); err == nil {
                        return nil
                }
 
index 91732d123dc5938bd0fccba1418e898a7f5d4d60..09a1d512f1e5fb548722313f4308a5d93890ae85 100644 (file)
@@ -21,12 +21,9 @@ func overlayDir(dstRoot, srcRoot string) error {
                return err
        }
 
-       symBase, err := filepath.Rel(srcRoot, dstRoot)
+       srcRoot, err := filepath.Abs(srcRoot)
        if err != nil {
-               symBase, err = filepath.Abs(srcRoot)
-               if err != nil {
-                       return err
-               }
+               return err
        }
 
        return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
@@ -52,11 +49,11 @@ func overlayDir(dstRoot, srcRoot string) error {
                // Always copy directories (don't symlink them).
                // If we add a file in the overlay, we don't want to add it in the original.
                if info.IsDir() {
-                       return os.Mkdir(dstPath, perm|0200)
+                       return os.MkdirAll(dstPath, perm|0200)
                }
 
                // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
+               if err := os.Symlink(srcPath, dstPath); err == nil {
                        return nil
                }
 
index 91732d123dc5938bd0fccba1418e898a7f5d4d60..09a1d512f1e5fb548722313f4308a5d93890ae85 100644 (file)
@@ -21,12 +21,9 @@ func overlayDir(dstRoot, srcRoot string) error {
                return err
        }
 
-       symBase, err := filepath.Rel(srcRoot, dstRoot)
+       srcRoot, err := filepath.Abs(srcRoot)
        if err != nil {
-               symBase, err = filepath.Abs(srcRoot)
-               if err != nil {
-                       return err
-               }
+               return err
        }
 
        return filepath.Walk(srcRoot, func(srcPath string, info os.FileInfo, err error) error {
@@ -52,11 +49,11 @@ func overlayDir(dstRoot, srcRoot string) error {
                // Always copy directories (don't symlink them).
                // If we add a file in the overlay, we don't want to add it in the original.
                if info.IsDir() {
-                       return os.Mkdir(dstPath, perm|0200)
+                       return os.MkdirAll(dstPath, perm|0200)
                }
 
                // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
+               if err := os.Symlink(srcPath, dstPath); err == nil {
                        return nil
                }
 
index 6e77b2e97b70808694006823a1492b9143fa85aa..c446d0891cf0b56af85cfc67844ca916b3181803 100644 (file)
@@ -21,9 +21,7 @@ func overlayDir(dstRoot, srcRoot string) error {
                return err
        }
 
-       // If we don't use the absolute path here, exec'ing make.bash fails with
-       // “too many levels of symbolic links”.
-       symBase, err := filepath.Abs(srcRoot)
+       srcRoot, err := filepath.Abs(srcRoot)
        if err != nil {
                return err
        }
@@ -51,11 +49,11 @@ func overlayDir(dstRoot, srcRoot string) error {
                // Always copy directories (don't symlink them).
                // If we add a file in the overlay, we don't want to add it in the original.
                if info.IsDir() {
-                       return os.Mkdir(dstPath, perm|0200)
+                       return os.MkdirAll(dstPath, perm|0200)
                }
 
                // If the OS supports symlinks, use them instead of copying bytes.
-               if err := os.Symlink(filepath.Join(symBase, suffix), dstPath); err == nil {
+               if err := os.Symlink(srcPath, dstPath); err == nil {
                        return nil
                }