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
This commit is contained in:
Nick Craig-Wood 2022-02-17 13:47:05 +00:00
parent 399fb5b7fb
commit 89f0e4df80

View File

@ -754,9 +754,21 @@ func (f *Fs) ListR(ctx context.Context, dir string, callback fs.ListRCallback) (
} }
// About gets quota information // About gets quota information
func (f *Fs) About(ctx context.Context) (*fs.Usage, error) { func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) {
var total, objects int64
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 var containers []swift.Container
var err error
err = f.pacer.Call(func() (bool, error) { err = f.pacer.Call(func() (bool, error) {
containers, err = f.c.ContainersAll(ctx, nil) containers, err = f.c.ContainersAll(ctx, nil)
return shouldRetry(ctx, err) return shouldRetry(ctx, err)
@ -764,12 +776,12 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("container listing failed: %w", err) return nil, fmt.Errorf("container listing failed: %w", err)
} }
var total, objects int64
for _, c := range containers { for _, c := range containers {
total += c.Bytes total += c.Bytes
objects += c.Count objects += c.Count
} }
usage := &fs.Usage{ }
usage = &fs.Usage{
Used: fs.NewUsageValue(total), // bytes in use Used: fs.NewUsageValue(total), // bytes in use
Objects: fs.NewUsageValue(objects), // objects in use Objects: fs.NewUsageValue(objects), // objects in use
} }