aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2025-07-21 08:44:09 -0700
committerchrislu <chris.lu@gmail.com>2025-07-21 08:44:09 -0700
commit784224d66f1e9f75083eaf4f45084c10e2a4afb5 (patch)
treeba7966eb0a2b15dee54244bc79a022ac952fc6cc
parentc196d03951a75d3b8976f556cb0400e5b522edeb (diff)
downloadseaweedfs-784224d66f1e9f75083eaf4f45084c10e2a4afb5.tar.xz
seaweedfs-784224d66f1e9f75083eaf4f45084c10e2a4afb5.zip
fix listing objects
-rw-r--r--weed/s3api/s3api_object_versioning.go25
1 files changed, 22 insertions, 3 deletions
diff --git a/weed/s3api/s3api_object_versioning.go b/weed/s3api/s3api_object_versioning.go
index e6b6f975b..97102b9dc 100644
--- a/weed/s3api/s3api_object_versioning.go
+++ b/weed/s3api/s3api_object_versioning.go
@@ -263,8 +263,23 @@ func (s3a *S3ApiServer) findVersionsRecursively(currentPath, relativePath string
entryPath := path.Join(relativePath, entry.Name)
// Skip if this doesn't match the prefix filter
- if prefix != "" && !strings.HasPrefix(entryPath, strings.TrimPrefix(prefix, "/")) {
- continue
+ // Normalize both entryPath and prefix to handle leading slash differences
+ if prefix != "" {
+ normalizedPrefix := strings.TrimPrefix(prefix, "/")
+ if normalizedPrefix != "" {
+ // For directories, also check if the directory name with trailing slash matches the prefix
+ entryPathWithSlash := entryPath
+ if entry.IsDirectory && !strings.HasSuffix(entryPathWithSlash, "/") {
+ entryPathWithSlash += "/"
+ }
+
+ // Check if either the entry path or the path with slash matches the prefix
+ if !strings.HasPrefix(entryPath, normalizedPrefix) &&
+ !strings.HasPrefix(entryPathWithSlash, normalizedPrefix) &&
+ !strings.HasPrefix(normalizedPrefix, entryPath) {
+ continue
+ }
+ }
}
if entry.IsDirectory {
@@ -715,7 +730,8 @@ func (s3a *S3ApiServer) ListObjectVersionsHandler(w http.ResponseWriter, r *http
// Parse query parameters
query := r.URL.Query()
- prefix := query.Get("prefix")
+ originalPrefix := query.Get("prefix") // Keep original prefix for response
+ prefix := originalPrefix // Use for internal processing
if prefix != "" && !strings.HasPrefix(prefix, "/") {
prefix = "/" + prefix
}
@@ -740,6 +756,9 @@ func (s3a *S3ApiServer) ListObjectVersionsHandler(w http.ResponseWriter, r *http
return
}
+ // Set the original prefix in the response (not the normalized internal prefix)
+ result.Prefix = originalPrefix
+
writeSuccessResponseXML(w, r, result)
}