Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

union: fix get free space for remotes which don't support it #6071

Nick Craig-Wood1e1af46a12af
diff --git a/backend/union/upstream/upstream.go b/backend/union/upstream/upstream.go
index 41f30f400..1a85d783f 100644
--- a/backend/union/upstream/upstream.go
+++ b/backend/union/upstream/upstream.go
@@ -259,22 +259,30 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
}
// GetFreeSpace get the free space of the fs
+//
+// This is returned as 0..math.MaxInt64-1 leaving math.MaxInt64 as a sentinel
func (f *Fs) GetFreeSpace() (int64, error) {
if atomic.LoadInt64(&f.cacheExpiry) <= time.Now().Unix() {
err := f.updateUsage()
if err != nil {
- return math.MaxInt64, ErrUsageFieldNotSupported
+ return math.MaxInt64 - 1, ErrUsageFieldNotSupported
}
}
f.cacheMutex.RLock()
defer f.cacheMutex.RUnlock()
if f.usage.Free == nil {
- return math.MaxInt64, ErrUsageFieldNotSupported
+ return math.MaxInt64 - 1, ErrUsageFieldNotSupported
+ }
+ free := *f.usage.Free
+ if free >= math.MaxInt64 {
+ free = math.MaxInt64 - 1
}
- return *f.usage.Free, nil
+ return free, nil
}
// GetUsedSpace get the used space of the fs
+//
+// This is returned as 0..math.MaxInt64-1 leaving math.MaxInt64 as a sentinel
func (f *Fs) GetUsedSpace() (int64, error) {
if atomic.LoadInt64(&f.cacheExpiry) <= time.Now().Unix() {
err := f.updateUsage()
@@ -287,7 +295,11 @@ func (f *Fs) GetUsedSpace() (int64, error) {
if f.usage.Used == nil {
return 0, ErrUsageFieldNotSupported
}
- return *f.usage.Used, nil
+ used := *f.usage.Used
+ if used >= math.MaxInt64 {
+ used = math.MaxInt64 - 1
+ }
+ return used, nil
}
// GetNumObjects get the number of objects of the fs