mirror of
https://github.com/rclone/rclone.git
synced 2025-04-16 16:18:52 +08:00
Merge f03e759f2944b8b9307e505da174090c989b7f93 into 0b9671313b14ffe839ecbd7dd2ae5ac7f6f05db8
This commit is contained in:
commit
cbe184b7cd
@ -22,11 +22,7 @@ func (p *EpLno) lno(upstreams []*upstream.Fs) (*upstream.Fs, error) {
|
||||
var minNumObj int64 = math.MaxInt64
|
||||
var lnoUpstream *upstream.Fs
|
||||
for _, u := range upstreams {
|
||||
numObj, err := u.GetNumObjects()
|
||||
if err != nil {
|
||||
fs.LogPrintf(fs.LogLevelNotice, nil,
|
||||
"Number of Objects is not supported for upstream %s, treating as 0", u.Name())
|
||||
}
|
||||
numObj := u.GetNumObjects()
|
||||
if minNumObj > numObj {
|
||||
minNumObj = numObj
|
||||
lnoUpstream = u
|
||||
@ -42,11 +38,7 @@ func (p *EpLno) lnoEntries(entries []upstream.Entry) (upstream.Entry, error) {
|
||||
var minNumObj int64 = math.MaxInt64
|
||||
var lnoEntry upstream.Entry
|
||||
for _, e := range entries {
|
||||
numObj, err := e.UpstreamFs().GetNumObjects()
|
||||
if err != nil {
|
||||
fs.LogPrintf(fs.LogLevelNotice, nil,
|
||||
"Number of Objects is not supported for upstream %s, treating as 0", e.UpstreamFs().Name())
|
||||
}
|
||||
numObj := e.UpstreamFs().GetNumObjects()
|
||||
if minNumObj > numObj {
|
||||
minNumObj = numObj
|
||||
lnoEntry = e
|
||||
|
@ -438,19 +438,37 @@ func (f *Fs) GetUsedSpace() (int64, error) {
|
||||
}
|
||||
|
||||
// GetNumObjects get the number of objects of the fs
|
||||
func (f *Fs) GetNumObjects() (int64, error) {
|
||||
func (f *Fs) GetNumObjects() int64 {
|
||||
var err error
|
||||
if f.cacheExpiry.Load() <= time.Now().Unix() {
|
||||
err := f.updateUsage()
|
||||
if err != nil {
|
||||
return 0, ErrUsageFieldNotSupported
|
||||
err = f.updateUsage()
|
||||
}
|
||||
|
||||
if f.usage.Objects == nil {
|
||||
uName := f.Name()
|
||||
fs.LogPrintf(
|
||||
fs.LogLevelWarning,
|
||||
nil,
|
||||
"Number of objects not supported for upstream %s, falling back to listing (this will be slower)...",
|
||||
uName,
|
||||
)
|
||||
count, _, _, err := operations.Count(context.Background(), f)
|
||||
if err == nil {
|
||||
fs.Debugf(nil, "Counted %d objects for upstream %s by listing", count, uName)
|
||||
f.cacheMutex.Lock()
|
||||
f.usage.Objects = &count
|
||||
f.cacheMutex.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fs.Errorf(nil, "Error getting number of objects, treating as 0: %v", err)
|
||||
return 0
|
||||
}
|
||||
|
||||
f.cacheMutex.RLock()
|
||||
defer f.cacheMutex.RUnlock()
|
||||
if f.usage.Objects == nil {
|
||||
return 0, ErrUsageFieldNotSupported
|
||||
}
|
||||
return *f.usage.Objects, nil
|
||||
return *f.usage.Objects
|
||||
}
|
||||
|
||||
func (f *Fs) updateUsage() (err error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user