From 89f0e4df809e80ea4fd1949927914f5c35dfd5a5 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 17 Feb 2022 13:47:05 +0000 Subject: [PATCH] swift: fix about so it shows info about the current container only Before this change `rclone about swift:container` would show aggregate info about all the containers, not just the one in use. This causes a problem if container listing is disabled (for example in the Blomp service). This fix makes `rclone about swift:container` show only the info about the given `container`. If aggregate info about all the containers is required then use `rclone about swift:`. See: https://forum.rclone.org/t/rclone-mount-blomp-problem/29151/18 --- backend/swift/swift.go | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/backend/swift/swift.go b/backend/swift/swift.go index 03b496301..5e3d96933 100644 --- a/backend/swift/swift.go +++ b/backend/swift/swift.go @@ -754,22 +754,34 @@ func (f *Fs) ListR(ctx context.Context, dir string, callback fs.ListRCallback) ( } // About gets quota information -func (f *Fs) About(ctx context.Context) (*fs.Usage, error) { - var containers []swift.Container - var err error - err = f.pacer.Call(func() (bool, error) { - containers, err = f.c.ContainersAll(ctx, nil) - return shouldRetry(ctx, err) - }) - if err != nil { - return nil, fmt.Errorf("container listing failed: %w", err) - } +func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) { var total, objects int64 - for _, c := range containers { - total += c.Bytes - objects += c.Count + if f.rootContainer != "" { + var container swift.Container + err = f.pacer.Call(func() (bool, error) { + container, _, err = f.c.Container(ctx, f.rootContainer) + return shouldRetry(ctx, err) + }) + if err != nil { + return nil, fmt.Errorf("container info failed: %w", err) + } + total = container.Bytes + objects = container.Count + } else { + var containers []swift.Container + err = f.pacer.Call(func() (bool, error) { + containers, err = f.c.ContainersAll(ctx, nil) + return shouldRetry(ctx, err) + }) + if err != nil { + return nil, fmt.Errorf("container listing failed: %w", err) + } + for _, c := range containers { + total += c.Bytes + objects += c.Count + } } - usage := &fs.Usage{ + usage = &fs.Usage{ Used: fs.NewUsageValue(total), // bytes in use Objects: fs.NewUsageValue(objects), // objects in use }