diff --git a/internal/misc/getfiles.go b/internal/misc/getfiles.go index 3c0eea1..552ff97 100644 --- a/internal/misc/getfiles.go +++ b/internal/misc/getfiles.go @@ -3,6 +3,7 @@ package misc import ( "debug/elf" "fmt" + "io/fs" "os" "path/filepath" @@ -39,6 +40,24 @@ func getFile(file string, required bool) (files []string, err error) { return RemoveDuplicates(files), nil } + // If the file is a symlink we need to do this to prevent an infinite recursion + // loop: + // Symlinks need special handling to prevent infinite recursion: + // 1) add the symlink to the list of files + // 2) set file to dereferenced target + // 4) continue this function to either walk it if the target is a dir or add the + // target to the list of files + if s, err := os.Lstat(file); err != nil { + return files, err + } else if s.Mode()&fs.ModeSymlink != 0 { + files = append(files, file) + if target, err := filepath.EvalSymlinks(file); err != nil { + return files, err + } else { + file = target + } + } + fileInfo, err := os.Stat(file) if err != nil { // Check if there is a Zstd-compressed version of the file