Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions cmd/hashets/hashets.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"path/filepath"
"sort"

"github.com/bmatcuk/doublestar"
doublestar "github.com/bmatcuk/doublestar/v4"

"github.com/mavolin/hashets/hashets"
"github.com/mavolin/hashets/internal/meta"
Expand Down Expand Up @@ -48,9 +48,8 @@ func init() {
"ignores paths that match the glob\n"+
"supports ** globs",
func(s string) error {
_, err := doublestar.PathMatch(s, "")
if err != nil {
return err
if !doublestar.ValidatePattern(s) {
return fmt.Errorf("invalid ignore pattern %q", s)
}

ignore = append(ignore, s)
Expand All @@ -61,9 +60,8 @@ func init() {
"if both -include and -ignore are set, a file must be included and not ignored to be hashed\n"+
"supports ** globs",
func(s string) error {
_, err := doublestar.PathMatch(s, "")
if err != nil {
return err
if !doublestar.ValidatePattern(s) {
return fmt.Errorf("invalid include pattern %q", s)
}

include = append(include, s)
Expand Down Expand Up @@ -170,10 +168,12 @@ func main() {
return true
}

// filepath.Clean to convert the slash-based fs path to an
// os-style path
needle := filepath.Clean(p)

for _, pattern := range ignore {
// filepath.Clean to convert the slash-based fs path to an
// os-style path
if match, _ := doublestar.PathMatch(pattern, filepath.Clean(p)); match {
if doublestar.PathMatchUnvalidated(pattern, needle) {
return true
}
}
Expand All @@ -183,7 +183,7 @@ func main() {
}

for _, pattern := range include {
if match, _ := doublestar.PathMatch(pattern, filepath.Clean(p)); match {
if doublestar.PathMatchUnvalidated(pattern, needle) {
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/mavolin/hashets
go 1.20

require (
github.com/bmatcuk/doublestar v1.3.4
github.com/bmatcuk/doublestar/v4 v4.9.1
github.com/stretchr/testify v1.8.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/bmatcuk/doublestar/v4 v4.9.1 h1:X8jg9rRZmJd4yRy7ZeNDRnM+T3ZfHv15JiBJ/avrEXE=
github.com/bmatcuk/doublestar/v4 v4.9.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
Loading