diff --git a/cmd/hashets/hashets.go b/cmd/hashets/hashets.go index 03565d3..fce6af0 100644 --- a/cmd/hashets/hashets.go +++ b/cmd/hashets/hashets.go @@ -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" @@ -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) @@ -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) @@ -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 } } @@ -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 } } diff --git a/go.mod b/go.mod index ce366b6..1c28b08 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 40b2433..2d4d09b 100644 --- a/go.sum +++ b/go.sum @@ -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=