Skip to content

Commit

Permalink
Resolve issue with directory symlinks in local replace. bazelbuild#1829
Browse files Browse the repository at this point in the history
  • Loading branch information
jtszalay authored Jun 20, 2024
1 parent 476a944 commit 9be8f0b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/fetch_repo/copy_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func copyTree(destRoot, srcRoot string) error {
if err != nil {
return err
}

if rel == "." {
return nil
}
Expand All @@ -39,6 +40,24 @@ func copyTree(destRoot, srcRoot string) error {
return os.Mkdir(dest, 0o777)
}

// Check if the current file is a symlink and if it's a directory
if info.Mode()&os.ModeSymlink != 0 {
linkTarget, err := filepath.EvalSymlinks(src)
if err != nil {
return err
}
linkInfo, err := os.Lstat(linkTarget)
if err != nil {
return err
}
if linkInfo.IsDir() {
// Rather than copying the directory symlink we create the dir and continue
// This resolves an issue where the walk attempts to copy files into the symlinked directory
// copy_file_range: is a directory
return os.Mkdir(dest, 0o777)
}
}

r, err := os.Open(src)
if err != nil {
return err
Expand Down

0 comments on commit 9be8f0b

Please sign in to comment.