Skip to content

Commit

Permalink
Merge pull request #164 from moov-io/fix-listfiles-mastercard
Browse files Browse the repository at this point in the history
fix: handle special case for listfiles
  • Loading branch information
adamdecaf authored Aug 28, 2023
2 parents 3eebd7b + 2a85d51 commit 0770cc2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ func (c *client) UploadFile(path string, contents io.ReadCloser) error {
// appear on the server.
func (c *client) ListFiles(dir string) ([]string, error) {
pattern := filepath.Clean(strings.TrimPrefix(dir, string(os.PathSeparator)))
wd := "."
var err error
switch {
case dir == "/":
pattern = "*"
Expand All @@ -387,11 +389,15 @@ func (c *client) ListFiles(dir string) ([]string, error) {
pattern = filepath.Join(dir, "*")
}
case pattern != "":
pattern += "/*"
pattern = "[/?]" + pattern + "/*"
wd, err = c.client.Getwd()
if err != nil {
return nil, err
}
}

var filenames []string
err := c.Walk(".", func(path string, d fs.DirEntry, err error) error {
err = c.Walk(wd, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
Expand All @@ -403,7 +409,8 @@ func (c *client) ListFiles(dir string) ([]string, error) {
matches, err := filepath.Match(strings.ToLower(pattern), strings.ToLower(path))
if matches && err == nil {
// Return the path with exactly the case on the server.
idx := strings.Index(strings.ToLower(path), strings.ToLower(strings.TrimSuffix(pattern, "*")))
trimmedPattern := strings.TrimPrefix(strings.TrimSuffix(pattern, "*"), "[/?]")
idx := strings.Index(strings.ToLower(path), strings.ToLower(trimmedPattern))
if idx > -1 {
path = path[idx:]
if strings.HasPrefix(dir, "/") && !strings.HasPrefix(path, "/") {
Expand Down

0 comments on commit 0770cc2

Please sign in to comment.