From ed047f5046564a144afd0345375c5e9bb4889877 Mon Sep 17 00:00:00 2001 From: jonaustin09 Date: Thu, 22 Jun 2023 19:52:55 +0400 Subject: [PATCH] fix: fixed directory object key prefix --- backend/posix/posix.go | 4 +++- backend/walk.go | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/posix/posix.go b/backend/posix/posix.go index 6245c7ac..459884f5 100644 --- a/backend/posix/posix.go +++ b/backend/posix/posix.go @@ -1071,9 +1071,11 @@ func fileToObj(bucket string) backend.GetObjFunc { return types.Object{}, fmt.Errorf("get fileinfo: %w", err) } + key := path + "/" + return types.Object{ ETag: &etag, - Key: &path, + Key: &key, LastModified: backend.GetTimePtr(fi.ModTime()), }, nil } diff --git a/backend/walk.go b/backend/walk.go index 0d312773..39bf8008 100644 --- a/backend/walk.go +++ b/backend/walk.go @@ -112,13 +112,13 @@ func Walk(fileSystem fs.FS, prefix, delimiter, marker string, max int, getObj Ge pastMarker = true } - // If object doesnt have prefix, dont include in results. + // If object doesn't have prefix, don't include in results. if prefix != "" && !strings.HasPrefix(path, prefix) { return nil } if delimiter == "" { - // If no delimeter specified, then all files with matching + // If no delimiter specified, then all files with matching // prefix are included in results obj, err := getObj(path, d) if err == ErrSkipObj { @@ -143,7 +143,7 @@ func Walk(fileSystem fs.FS, prefix, delimiter, marker string, max int, getObj Ge // // For example: // prefix = A/ - // delimeter = / + // delimiter = / // and objects: // A/file // A/B/file @@ -152,11 +152,11 @@ func Walk(fileSystem fs.FS, prefix, delimiter, marker string, max int, getObj Ge // objects: A/file // common prefix: A/B/ // - // Note: No obects are included past the common prefix since + // Note: No objects are included past the common prefix since // these are all rolled up into the common prefix. - // Note: The delimeter can be anything, so we have to operate on + // Note: The delimiter can be anything, so we have to operate on // the full path without any assumptions on posix directory hierarchy - // here. Usually the delimeter will be "/", but thats not required. + // here. Usually the delimiter will be "/", but thats not required. suffix := strings.TrimPrefix(path, prefix) before, _, found := strings.Cut(suffix, delimiter) if !found { @@ -176,7 +176,7 @@ func Walk(fileSystem fs.FS, prefix, delimiter, marker string, max int, getObj Ge // Common prefixes are a set, so should not have duplicates. // These are abstractly a "directory", so need to include the - // delimeter at the end. + // delimiter at the end. cpmap[prefix+before+delimiter] = struct{}{} if (len(objects) + len(cpmap)) == max { pastMax = true