Skip to content

Commit

Permalink
Fix license loading failure due to directory symlink (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: Emruz Hossain <[email protected]>
  • Loading branch information
Emruz Hossain authored Feb 17, 2023
1 parent 2c78c88 commit ba17385
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/storage/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ func LoadDir(cid, dir string, reg *LicenseRegistry) error {
continue
}

dirLink, err := isSymlinkToDir(dir, entry)
if err != nil {
return err
}
if dirLink {
continue
}

filename := filepath.Join(dir, entry.Name())
data, err := os.ReadFile(filename)
if err != nil {
Expand All @@ -66,3 +74,18 @@ func LoadDir(cid, dir string, reg *LicenseRegistry) error {
}
return nil
}

func isSymlinkToDir(dir string, entry os.DirEntry) (bool, error) {
if entry.Type() != os.ModeSymlink {
return false, nil
}
path, err := filepath.EvalSymlinks(filepath.Join(dir, entry.Name()))
if err != nil {
return false, err
}
stats, err := os.Stat(path)
if err != nil {
return false, err
}
return stats.IsDir(), nil
}

0 comments on commit ba17385

Please sign in to comment.