Skip to content

Commit

Permalink
misc: remove use of relative directories in overlayDir functions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Bryan C. Mills committed Nov 25, 2019
1 parent 01f15b6 commit 476395c
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 68 deletions.
11 changes: 4 additions & 7 deletions misc/cgo/life/overlaydir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
11 changes: 4 additions & 7 deletions misc/cgo/stdio/overlaydir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
11 changes: 4 additions & 7 deletions misc/cgo/test/overlaydir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
11 changes: 4 additions & 7 deletions misc/cgo/testcarchive/overlaydir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
11 changes: 4 additions & 7 deletions misc/cgo/testcshared/overlaydir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
11 changes: 4 additions & 7 deletions misc/cgo/testplugin/overlaydir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
11 changes: 4 additions & 7 deletions misc/cgo/testshared/overlaydir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
11 changes: 4 additions & 7 deletions misc/cgo/testso/overlaydir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
11 changes: 4 additions & 7 deletions misc/cgo/testsovar/overlaydir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
8 changes: 3 additions & 5 deletions misc/reboot/overlaydir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 476395c

Please sign in to comment.