diff --git a/backend/swift/swift.go b/backend/swift/swift.go index 8549519b5..127ea0402 100644 --- a/backend/swift/swift.go +++ b/backend/swift/swift.go @@ -545,7 +545,7 @@ type listFn func(remote string, object *swift.Object, isDirectory bool) error // container to the start. // // Set recurse to read sub directories -func (f *Fs) listContainerRoot(container, directory, prefix string, addContainer bool, recurse bool, fn listFn) error { +func (f *Fs) listContainerRoot(container, directory, prefix string, addContainer bool, recurse bool, includeDirMarkers bool, fn listFn) error { if prefix != "" && !strings.HasSuffix(prefix, "/") { prefix += "/" } @@ -579,7 +579,7 @@ func (f *Fs) listContainerRoot(container, directory, prefix string, addContainer fs.Logf(f, "Odd name received %q", remote) continue } - if remote == prefix { + if !includeDirMarkers && remote == prefix { // If we have zero length directory markers ending in / then swift // will return them in the listing for the directory which causes // duplicate directories. Ignore them here. @@ -602,8 +602,8 @@ func (f *Fs) listContainerRoot(container, directory, prefix string, addContainer type addEntryFn func(fs.DirEntry) error // list the objects into the function supplied -func (f *Fs) list(container, directory, prefix string, addContainer bool, recurse bool, fn addEntryFn) error { - err := f.listContainerRoot(container, directory, prefix, addContainer, recurse, func(remote string, object *swift.Object, isDirectory bool) (err error) { +func (f *Fs) list(container, directory, prefix string, addContainer bool, recurse bool, includeDirMarkers bool, fn addEntryFn) error { + err := f.listContainerRoot(container, directory, prefix, addContainer, recurse, includeDirMarkers, func(remote string, object *swift.Object, isDirectory bool) (err error) { if isDirectory { remote = strings.TrimRight(remote, "/") d := fs.NewDir(remote, time.Time{}).SetSize(object.Bytes) @@ -615,7 +615,7 @@ func (f *Fs) list(container, directory, prefix string, addContainer bool, recurs if err != nil { return err } - if o.Storable() { + if includeDirMarkers || o.Storable() { err = fn(o) } } @@ -633,7 +633,7 @@ func (f *Fs) listDir(container, directory, prefix string, addContainer bool) (en return nil, fs.ErrorListBucketRequired } // List the objects - err = f.list(container, directory, prefix, addContainer, false, func(entry fs.DirEntry) error { + err = f.list(container, directory, prefix, addContainer, false, false, func(entry fs.DirEntry) error { entries = append(entries, entry) return nil }) @@ -703,7 +703,7 @@ func (f *Fs) ListR(ctx context.Context, dir string, callback fs.ListRCallback) ( container, directory := f.split(dir) list := walk.NewListRHelper(callback) listR := func(container, directory, prefix string, addContainer bool) error { - return f.list(container, directory, prefix, addContainer, true, func(entry fs.DirEntry) error { + return f.list(container, directory, prefix, addContainer, true, false, func(entry fs.DirEntry) error { return list.Add(entry) }) } @@ -850,7 +850,7 @@ func (f *Fs) Purge(ctx context.Context) error { go func() { delErr <- operations.DeleteFiles(ctx, toBeDeleted) }() - err := f.list(f.rootContainer, f.rootDirectory, f.rootDirectory, f.rootContainer == "", true, func(entry fs.DirEntry) error { + err := f.list(f.rootContainer, f.rootDirectory, f.rootDirectory, f.rootContainer == "", true, true, func(entry fs.DirEntry) error { if o, ok := entry.(*Object); ok { toBeDeleted <- o } @@ -1112,7 +1112,7 @@ func min(x, y int64) int64 { // if except is passed in then segments with that prefix won't be deleted func (o *Object) removeSegments(except string) error { segmentsContainer, prefix, err := o.getSegmentsDlo() - err = o.fs.listContainerRoot(segmentsContainer, prefix, "", false, true, func(remote string, object *swift.Object, isDirectory bool) error { + err = o.fs.listContainerRoot(segmentsContainer, prefix, "", false, true, true, func(remote string, object *swift.Object, isDirectory bool) error { if isDirectory { return nil }