Skip to content

Commit

Permalink
fix symlink in inputs (#367)
Browse files Browse the repository at this point in the history
* ignore the symlink itself when traversing the filetree
  • Loading branch information
Equanox authored Jan 26, 2024
1 parent c181f00 commit cc10425
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/filepathutil/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func listDir(path string, projectRoot string) (all []string, symlinkErrors []err
// Append file
if fi.IsDir() {
return nil

}

fileInfo, err := fi.Info()
Expand Down Expand Up @@ -156,11 +155,8 @@ func listDir(path string, projectRoot string) (all []string, symlinkErrors []err
//
// The returned error contains a "failed to follow symlink" hint and should
// be presented to the user.
//
// filepathHint is used to get around the
func isValidFile(path string, info fs.FileInfo, projectRoot string) (bool, error) {
if info.Mode()&os.ModeSymlink != 0 {

sym, err := filepath.EvalSymlinks(path)
if err != nil {
return false, fmt.Errorf("failed to follow symlink %q: %w", path, err)
Expand All @@ -177,6 +173,10 @@ func isValidFile(path string, info fs.FileInfo, projectRoot string) (bool, error
if !strings.HasPrefix(absSym, projectRoot) {
return false, fmt.Errorf("symbolic link [%s] points to a location [%s] outside of the project [%s]", path, sym, projectRoot)
}

// the symlink itself should not appear in the input list
// only the resolved path should be added.
return false, nil
}

return true, nil
Expand Down

0 comments on commit cc10425

Please sign in to comment.