Skip to content

Commit

Permalink
fix: Remove redundant path joins.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgeiser committed Nov 6, 2020
1 parent 79878ac commit 11ce768
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 4 additions & 5 deletions glob.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package zglob
import (
"fmt"
"os"
"path"

"github.com/gobwas/glob"
"github.com/spf13/afero"
Expand Down Expand Up @@ -51,20 +50,20 @@ func GlobWithFs(fs afero.Fs, pattern string) ([]string, error) {
return err
}

if !matcher.Match(info.Name()) {
if !matcher.Match(currentPath) {
return nil
}

if info.IsDir() {
// a direct match on a directory implies that all files inside match
filesInDir, err := filesInDirectory(fs, path.Join(currentPath, info.Name()))
filesInDir, err := filesInDirectory(fs, currentPath)
if err != nil {
return err
}

matches = append(matches, filesInDir...)
} else {
matches = append(matches, path.Join(currentPath, info.Name()))
matches = append(matches, currentPath)
}

return nil
Expand All @@ -83,7 +82,7 @@ func filesInDirectory(fs afero.Fs, dir string) ([]string, error) {
return nil
}

files = append(files, path.Join(currentPath, info.Name()))
files = append(files, currentPath)

return nil
})
Expand Down
3 changes: 1 addition & 2 deletions prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package zglob

import (
"fmt"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -46,7 +45,7 @@ func staticPrefix(pattern string) (string, error) {
break
}

prefix = path.Join(prefix, v.Text)
prefix = filepath.Join(prefix, v.Text)
}

if prefix == "" {
Expand Down

0 comments on commit 11ce768

Please sign in to comment.