Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve issue with directory symlinks in local replace. #1829 #1830

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cmd/fetch_repo/copy_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of EvalSymlinks and Lstat, could we just use Stat?

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 link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the precise problem that the walk saw the symlink as not a directory (since the FileInfo comes from an Lstat) and this tried to copy over a file to what should be a directory?

// copy_file_range: is a directory
return os.Mkdir(dest, 0o777)
}
}

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