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 5, 2022
1 parent fbd2659 commit b62998e
Showing 1 changed file with 15 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

0 comments on commit b62998e

Please sign in to comment.