mirror of
https://github.com/rclone/rclone.git
synced 2025-03-01 08:51:58 +01:00
union: fix description and variable names of epff, epmfs, mfs policies
This commit is contained in:
parent
da9a44ea5e
commit
36e184266f
@ -17,19 +17,19 @@ type EpFF struct {}
|
|||||||
|
|
||||||
func (p *EpFF) epff(ctx context.Context, upstreams []*upstream.Fs, path string) (*upstream.Fs, error) {
|
func (p *EpFF) epff(ctx context.Context, upstreams []*upstream.Fs, path string) (*upstream.Fs, error) {
|
||||||
ch := make(chan *upstream.Fs)
|
ch := make(chan *upstream.Fs)
|
||||||
for _, r := range upstreams {
|
for _, u := range upstreams {
|
||||||
r := r // Closure
|
u := u // Closure
|
||||||
go func() {
|
go func() {
|
||||||
if !exists(ctx, r, path) {
|
if !exists(ctx, u, path) {
|
||||||
r = nil
|
u = nil
|
||||||
}
|
}
|
||||||
ch <- r
|
ch <- u
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
var r *upstream.Fs
|
var u *upstream.Fs
|
||||||
for i := 0; i < len(upstreams); i++ {
|
for i := 0; i < len(upstreams); i++ {
|
||||||
r = <- ch
|
u = <- ch
|
||||||
if r != nil {
|
if u != nil {
|
||||||
// close remaining goroutines
|
// close remaining goroutines
|
||||||
go func(num int) {
|
go func(num int) {
|
||||||
defer close(ch)
|
defer close(ch)
|
||||||
@ -39,10 +39,10 @@ func (p *EpFF) epff(ctx context.Context, upstreams []*upstream.Fs, path string)
|
|||||||
}(len(upstreams) - 1 - i)
|
}(len(upstreams) - 1 - i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if r == nil {
|
if u == nil {
|
||||||
return nil, fs.ErrorObjectNotFound
|
return nil, fs.ErrorObjectNotFound
|
||||||
}
|
}
|
||||||
return r, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action category policy, governing the modification of files and directories
|
// Action category policy, governing the modification of files and directories
|
||||||
@ -54,8 +54,8 @@ func (p *EpFF) Action(ctx context.Context, upstreams []*upstream.Fs, path string
|
|||||||
if len(upstreams) == 0 {
|
if len(upstreams) == 0 {
|
||||||
return nil, fs.ErrorPermissionDenied
|
return nil, fs.ErrorPermissionDenied
|
||||||
}
|
}
|
||||||
r, err := p.epff(ctx, upstreams, path)
|
u, err := p.epff(ctx, upstreams, path)
|
||||||
return []*upstream.Fs{r}, err
|
return []*upstream.Fs{u}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionEntries is ACTION category policy but receving a set of candidate entries
|
// ActionEntries is ACTION category policy but receving a set of candidate entries
|
||||||
@ -79,8 +79,8 @@ func (p *EpFF) Create(ctx context.Context, upstreams []*upstream.Fs, path string
|
|||||||
if len(upstreams) == 0 {
|
if len(upstreams) == 0 {
|
||||||
return nil, fs.ErrorPermissionDenied
|
return nil, fs.ErrorPermissionDenied
|
||||||
}
|
}
|
||||||
r, err := p.epff(ctx, upstreams, path)
|
u, err := p.epff(ctx, upstreams, path)
|
||||||
return []*upstream.Fs{r}, err
|
return []*upstream.Fs{u}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateEntries is CREATE category policy but receving a set of candidate entries
|
// CreateEntries is CREATE category policy but receving a set of candidate entries
|
||||||
|
@ -12,7 +12,7 @@ func init(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EpMfs stands for existing path, most free space
|
// EpMfs stands for existing path, most free space
|
||||||
// Of all the branches on which the path exists choose the drive with the most free space.
|
// Of all the candidates on which the path exists choose the one with the most free space.
|
||||||
type EpMfs struct {
|
type EpMfs struct {
|
||||||
EpAll
|
EpAll
|
||||||
}
|
}
|
||||||
@ -20,16 +20,19 @@ type EpMfs struct {
|
|||||||
func (p *EpMfs) mfs(upstreams []*upstream.Fs) (*upstream.Fs, error) {
|
func (p *EpMfs) mfs(upstreams []*upstream.Fs) (*upstream.Fs, error) {
|
||||||
var maxFreeSpace int64
|
var maxFreeSpace int64
|
||||||
var mfsupstream *upstream.Fs
|
var mfsupstream *upstream.Fs
|
||||||
for _, r := range upstreams {
|
for _, u := range upstreams {
|
||||||
space, err := r.GetFreeSpace()
|
space, err := u.GetFreeSpace()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if maxFreeSpace < space {
|
if maxFreeSpace < space {
|
||||||
maxFreeSpace = space
|
maxFreeSpace = space
|
||||||
mfsupstream = r
|
mfsupstream = u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if mfsupstream == nil {
|
||||||
|
return nil, fs.ErrorObjectNotFound
|
||||||
|
}
|
||||||
return mfsupstream, nil
|
return mfsupstream, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +58,8 @@ func (p *EpMfs) Action(ctx context.Context, upstreams []*upstream.Fs, path strin
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
r, err := p.mfs(upstreams)
|
u, err := p.mfs(upstreams)
|
||||||
return []*upstream.Fs{r}, err
|
return []*upstream.Fs{u}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionEntries is ACTION category policy but receving a set of candidate entries
|
// ActionEntries is ACTION category policy but receving a set of candidate entries
|
||||||
@ -75,8 +78,8 @@ func (p *EpMfs) Create(ctx context.Context, upstreams []*upstream.Fs, path strin
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
r, err := p.mfs(upstreams)
|
u, err := p.mfs(upstreams)
|
||||||
return []*upstream.Fs{r}, err
|
return []*upstream.Fs{u}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateEntries is CREATE category policy but receving a set of candidate entries
|
// CreateEntries is CREATE category policy but receving a set of candidate entries
|
||||||
|
@ -12,7 +12,9 @@ func init(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Mfs stands for most free space
|
// Mfs stands for most free space
|
||||||
// Of all the candidates on which the path exists choose the one with the most free space.
|
// Search category: same as epmfs.
|
||||||
|
// Action category: same as epmfs.
|
||||||
|
// Create category: Pick the drive with the most free space.
|
||||||
type Mfs struct {
|
type Mfs struct {
|
||||||
EpMfs
|
EpMfs
|
||||||
}
|
}
|
||||||
@ -26,6 +28,6 @@ func (p *Mfs) Create(ctx context.Context, upstreams []*upstream.Fs, path string)
|
|||||||
if len(upstreams) == 0 {
|
if len(upstreams) == 0 {
|
||||||
return nil, fs.ErrorPermissionDenied
|
return nil, fs.ErrorPermissionDenied
|
||||||
}
|
}
|
||||||
r, err := p.mfs(upstreams)
|
u, err := p.mfs(upstreams)
|
||||||
return []*upstream.Fs{r}, err
|
return []*upstream.Fs{u}, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user