Skip to content

Commit

Permalink
fix: issue with symlinks in directories for nfpm
Browse files Browse the repository at this point in the history
  • Loading branch information
Felixoid committed Feb 9, 2022
1 parent 80e86ff commit 6e8a94d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions glob.go
Expand Up @@ -124,6 +124,13 @@ func Glob(pattern string, opts ...OptFunc) ([]string, error) { // nolint:funlen,
return nil, fmt.Errorf("cannot determine static prefix: %w", err)
}

// Check if the file is valid symlink without following it
if prefixInfo, err := os.Lstat(pattern); err == nil {
if prefixInfo.Mode()&os.ModeSymlink == os.ModeSymlink {
return cleanFilepaths([]string{pattern}, options.prefix), nil
}
}

prefixInfo, err := fs.Stat(options.fs, prefix)
if errors.Is(err, fs.ErrNotExist) {
if !ContainsMatchers(pattern) {
Expand Down
19 changes: 19 additions & 0 deletions glob_test.go
Expand Up @@ -450,6 +450,25 @@ func TestGlob(t *testing.T) { // nolint:funlen
"a/b/4.txt",
}, matches)
})

t.Run("symlinks", func(t *testing.T) {
t.Parallel()
testFS := testFs(t, []string{
"./a/file",
}, nil).(testfs.FS)

fsPath := testFS.Path()
os.Symlink("file", filepath.Join(fsPath, "./a/working-symlink"))
os.Symlink("non-existent", filepath.Join(fsPath, "./a/broken-symlink"))

matches, err := Glob("a/*", MatchDirectoryIncludesContents, WithFs(testFS))
require.NoError(t, err)
require.Equal(t, []string{
"a/broken-symlink",
"a/file",
"a/working-symlink",
}, matches)
})
}

func TestQuoteMeta(t *testing.T) {
Expand Down

0 comments on commit 6e8a94d

Please sign in to comment.