From 26bc9826e569be6f56ec6289c0122c52d0611e7f Mon Sep 17 00:00:00 2001 From: fsantagostinobietti <6057026+fsantagostinobietti@users.noreply.github.com> Date: Thu, 29 Aug 2024 11:29:22 +0200 Subject: [PATCH] swift: add total/free space info in about command. With the enhancement in version v2.0.3 of ncw/swift library, we can now get Total and Free space info from remotes that support this feature (ex. Blomp storage) --- backend/swift/swift.go | 14 ++++++++++---- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/backend/swift/swift.go b/backend/swift/swift.go index edc774248..452d5f11a 100644 --- a/backend/swift/swift.go +++ b/backend/swift/swift.go @@ -883,7 +883,7 @@ func (f *Fs) ListR(ctx context.Context, dir string, callback fs.ListRCallback) ( // About gets quota information func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) { - var total, objects int64 + var used, objects, total int64 if f.rootContainer != "" { var container swift.Container err = f.pacer.Call(func() (bool, error) { @@ -893,8 +893,9 @@ func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) { if err != nil { return nil, fmt.Errorf("container info failed: %w", err) } - total = container.Bytes + used = container.Bytes objects = container.Count + total = container.QuotaBytes } else { var containers []swift.Container err = f.pacer.Call(func() (bool, error) { @@ -905,14 +906,19 @@ func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) { return nil, fmt.Errorf("container listing failed: %w", err) } for _, c := range containers { - total += c.Bytes + used += c.Bytes objects += c.Count + total += c.QuotaBytes } } usage = &fs.Usage{ - Used: fs.NewUsageValue(total), // bytes in use + Used: fs.NewUsageValue(used), // bytes in use Objects: fs.NewUsageValue(objects), // objects in use } + if total > 0 { + usage.Total = fs.NewUsageValue(total) + usage.Free = fs.NewUsageValue(total - used) + } return usage, nil } diff --git a/go.mod b/go.mod index c26d5f49b..e860ff31a 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/minio/minio-go/v7 v7.0.74 github.com/mitchellh/go-homedir v1.1.0 github.com/moby/sys/mountinfo v0.7.2 - github.com/ncw/swift/v2 v2.0.2 + github.com/ncw/swift/v2 v2.0.3 github.com/oracle/oci-go-sdk/v65 v65.69.2 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pkg/sftp v1.13.6 diff --git a/go.sum b/go.sum index 62cebef03..3b48fdf64 100644 --- a/go.sum +++ b/go.sum @@ -461,8 +461,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/ncw/swift/v2 v2.0.2 h1:jx282pcAKFhmoZBSdMcCRFn9VWkoBIRsCpe+yZq7vEk= -github.com/ncw/swift/v2 v2.0.2/go.mod h1:z0A9RVdYPjNjXVo2pDOPxZ4eu3oarO1P91fTItcb+Kg= +github.com/ncw/swift/v2 v2.0.3 h1:8R9dmgFIWs+RiVlisCEfiQiik1hjuR0JnOkLxaP9ihg= +github.com/ncw/swift/v2 v2.0.3/go.mod h1:cbAO76/ZwcFrFlHdXPjaqWZ9R7Hdar7HpjRXBfbjigk= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=