union: add min_free_space option for lfs/eplfs policies - fixes #6071
This commit is contained in:
@@ -2,6 +2,7 @@ package policy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/rclone/rclone/backend/union/upstream"
|
||||
@@ -18,6 +19,8 @@ type EpLfs struct {
|
||||
EpAll
|
||||
}
|
||||
|
||||
var errNoUpstreamsFound = errors.New("no upstreams found with more than min_free_space space spare")
|
||||
|
||||
func (p *EpLfs) lfs(upstreams []*upstream.Fs) (*upstream.Fs, error) {
|
||||
var minFreeSpace int64 = math.MaxInt64
|
||||
var lfsupstream *upstream.Fs
|
||||
@@ -27,31 +30,35 @@ func (p *EpLfs) lfs(upstreams []*upstream.Fs) (*upstream.Fs, error) {
|
||||
fs.LogPrintf(fs.LogLevelNotice, nil,
|
||||
"Free Space is not supported for upstream %s, treating as infinite", u.Name())
|
||||
}
|
||||
if space < minFreeSpace {
|
||||
if space < minFreeSpace && space > int64(u.Opt.MinFreeSpace) {
|
||||
minFreeSpace = space
|
||||
lfsupstream = u
|
||||
}
|
||||
}
|
||||
if lfsupstream == nil {
|
||||
return nil, fs.ErrorObjectNotFound
|
||||
return nil, errNoUpstreamsFound
|
||||
}
|
||||
return lfsupstream, nil
|
||||
}
|
||||
|
||||
func (p *EpLfs) lfsEntries(entries []upstream.Entry) (upstream.Entry, error) {
|
||||
var minFreeSpace int64
|
||||
var minFreeSpace int64 = math.MaxInt64
|
||||
var lfsEntry upstream.Entry
|
||||
for _, e := range entries {
|
||||
space, err := e.UpstreamFs().GetFreeSpace()
|
||||
u := e.UpstreamFs()
|
||||
space, err := u.GetFreeSpace()
|
||||
if err != nil {
|
||||
fs.LogPrintf(fs.LogLevelNotice, nil,
|
||||
"Free Space is not supported for upstream %s, treating as infinite", e.UpstreamFs().Name())
|
||||
"Free Space is not supported for upstream %s, treating as infinite", u.Name())
|
||||
}
|
||||
if space < minFreeSpace {
|
||||
if space < minFreeSpace && space > int64(u.Opt.MinFreeSpace) {
|
||||
minFreeSpace = space
|
||||
lfsEntry = e
|
||||
}
|
||||
}
|
||||
if lfsEntry == nil {
|
||||
return nil, errNoUpstreamsFound
|
||||
}
|
||||
return lfsEntry, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user