Skip to content

Commit

Permalink
refactor: cleanup symlink handling
Browse files Browse the repository at this point in the history
Simplify the `CopyDir` codepath around symlinks; this will help
since afero's MemMapFs still does not support symlinks.

Also remove the comment that was a bald-faced lie.
  • Loading branch information
nisimond authored and retr0h committed Feb 21, 2024
1 parent a30f9b3 commit bc0f5b7
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions internal/repository/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (r *Copy) CopyFile(

// CopyDir recursively copies a directory tree, attempting to preserve permissions.
// Source directory must exist, destination directory must *not* exist.
// Symlinks are ignored and skipped.
// Symlinks are implicitly dereferenced.
func (r *Copy) CopyDir(
src string,
dst string,
Expand Down Expand Up @@ -149,17 +149,10 @@ func (r *Copy) CopyDir(
srcPath := filepath.Join(src, entry.Name())
dstPath := filepath.Join(dst, entry.Name())

// If a symlink, we copy the contents
if entry.Mode()&os.ModeSymlink != 0 {
target, err := filepath.EvalSymlinks(srcPath)
if err != nil {
return err
}

entry, err = r.appFs.Stat(target)
if err != nil {
return err
}
// Dereference any symlinks and copy their contents instead
entry, err = r.appFs.Stat(srcPath)
if err != nil {
return err
}

if entry.IsDir() {
Expand Down

0 comments on commit bc0f5b7

Please sign in to comment.