Skip to content

Commit

Permalink
Honor ListObjects IncludeTrailingDelimiter
Browse files Browse the repository at this point in the history
This allows gcsfuse to list directory objects which end with / and
allows pjdfstest rmdir/06.t to pass.  References
GoogleCloudPlatform/gcsfuse#590.
  • Loading branch information
gaul committed Feb 12, 2022
1 parent fbd2659 commit b973949
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
25 changes: 15 additions & 10 deletions fakestorage/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,12 @@ func (s *Server) createObject(obj Object) (Object, error) {
}

type ListOptions struct {
Prefix string
Delimiter string
Versions bool
StartOffset string
EndOffset string
Prefix string
Delimiter string
Versions bool
StartOffset string
EndOffset string
IncludeTrailingDelimiter bool
}

// ListObjects returns a sorted list of objects that match the given criteria,
Expand Down Expand Up @@ -306,6 +307,9 @@ func (s *Server) ListObjectsWithOptions(bucketName string, options ListOptions)
if isInOffset(prefix, options.StartOffset, options.EndOffset) {
prefixes[prefix] = true
}
if options.IncludeTrailingDelimiter && obj.Name == prefix {
respObjects = append(respObjects, obj)
}
} else {
if isInOffset(obj.Name, options.StartOffset, options.EndOffset) {
respObjects = append(respObjects, obj)
Expand Down Expand Up @@ -453,11 +457,12 @@ func (s *Server) objectWithGenerationOnValidGeneration(bucketName, objectName, g
func (s *Server) listObjects(r *http.Request) jsonResponse {
bucketName := mux.Vars(r)["bucketName"]
objs, prefixes, err := s.ListObjectsWithOptions(bucketName, ListOptions{
Prefix: r.URL.Query().Get("prefix"),
Delimiter: r.URL.Query().Get("delimiter"),
Versions: r.URL.Query().Get("versions") == "true",
StartOffset: r.URL.Query().Get("startOffset"),
EndOffset: r.URL.Query().Get("endOffset"),
Prefix: r.URL.Query().Get("prefix"),
Delimiter: r.URL.Query().Get("delimiter"),
Versions: r.URL.Query().Get("versions") == "true",
StartOffset: r.URL.Query().Get("startOffset"),
EndOffset: r.URL.Query().Get("endOffset"),
IncludeTrailingDelimiter: r.URL.Query().Get("includeTrailingDelimiter") == "true",
})
if err != nil {
return jsonResponse{status: http.StatusNotFound}
Expand Down
15 changes: 15 additions & 0 deletions fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ func getObjectsForListTests() []Object {
{ObjectAttrs: ObjectAttrs{BucketName: "some-bucket", Name: "img/brand.jpg"}},
{ObjectAttrs: ObjectAttrs{BucketName: "some-bucket", Name: "video/hi-res/some_video_1080p.mp4"}},
{ObjectAttrs: ObjectAttrs{BucketName: "other-bucket", Name: "static/css/style.css"}},
{ObjectAttrs: ObjectAttrs{BucketName: "trailing-delimiter-bucket", Name: "foo/"}},
}
}

Expand Down Expand Up @@ -731,6 +732,20 @@ func getTestCasesForListTests(versioningEnabled, withOverwrites bool) []listTest
[]string{"img/brand.jpg"},
[]string{"img/hi-res/"},
},
{
"delimiter without IncludeTrailingDelimiter",
"trailing-delimiter-bucket",
&storage.Query{Delimiter: "/", IncludeTrailingDelimiter: false},
[]string{},
[]string{"foo/"},
},
{
"delimiter with IncludeTrailingDelimiter",
"trailing-delimiter-bucket",
&storage.Query{Delimiter: "/", IncludeTrailingDelimiter: true},
[]string{"foo/"},
[]string{"foo/"},
},
}
}

Expand Down

0 comments on commit b973949

Please sign in to comment.