forked from TrueCloudLab/rclone
union: fix get free space for remotes which don't support it #6071
Before this fix GetFreeSpace returned math.MaxInt64 for remotes which don't support reading free space, however this is used in various comparison routines as a too large value, meaning that remotes of size math.MaxInt64 were never being selected. This fixes GetFreeSpace to return math.MaxInt64 - 1 so then can be selected. It also fixes GetUsedSpace the same way however as the default for not supported was 0 this was very unlikely to have ever caused a problem.
This commit is contained in:
parent
1d2fe0d856
commit
1e1af46a12
1 changed files with 16 additions and 4 deletions
|
@ -259,22 +259,30 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFreeSpace get the free space of the fs
|
// 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) {
|
func (f *Fs) GetFreeSpace() (int64, error) {
|
||||||
if atomic.LoadInt64(&f.cacheExpiry) <= time.Now().Unix() {
|
if atomic.LoadInt64(&f.cacheExpiry) <= time.Now().Unix() {
|
||||||
err := f.updateUsage()
|
err := f.updateUsage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return math.MaxInt64, ErrUsageFieldNotSupported
|
return math.MaxInt64 - 1, ErrUsageFieldNotSupported
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.cacheMutex.RLock()
|
f.cacheMutex.RLock()
|
||||||
defer f.cacheMutex.RUnlock()
|
defer f.cacheMutex.RUnlock()
|
||||||
if f.usage.Free == nil {
|
if f.usage.Free == nil {
|
||||||
return math.MaxInt64, ErrUsageFieldNotSupported
|
return math.MaxInt64 - 1, ErrUsageFieldNotSupported
|
||||||
}
|
}
|
||||||
return *f.usage.Free, nil
|
free := *f.usage.Free
|
||||||
|
if free >= math.MaxInt64 {
|
||||||
|
free = math.MaxInt64 - 1
|
||||||
|
}
|
||||||
|
return free, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUsedSpace get the used space of the fs
|
// 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) {
|
func (f *Fs) GetUsedSpace() (int64, error) {
|
||||||
if atomic.LoadInt64(&f.cacheExpiry) <= time.Now().Unix() {
|
if atomic.LoadInt64(&f.cacheExpiry) <= time.Now().Unix() {
|
||||||
err := f.updateUsage()
|
err := f.updateUsage()
|
||||||
|
@ -287,7 +295,11 @@ func (f *Fs) GetUsedSpace() (int64, error) {
|
||||||
if f.usage.Used == nil {
|
if f.usage.Used == nil {
|
||||||
return 0, ErrUsageFieldNotSupported
|
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
|
// GetNumObjects get the number of objects of the fs
|
||||||
|
|
Loading…
Add table
Reference in a new issue