union: fix description and variable names of epff, epmfs, mfs policies

This commit is contained in:
Max Sum 2019-12-01 00:35:52 +08:00 committed by Nick Craig-Wood
parent da9a44ea5e
commit 36e184266f
3 changed files with 30 additions and 25 deletions

View File

@ -17,19 +17,19 @@ type EpFF struct {}
func (p *EpFF) epff(ctx context.Context, upstreams []*upstream.Fs, path string) (*upstream.Fs, error) {
ch := make(chan *upstream.Fs)
for _, r := range upstreams {
r := r // Closure
for _, u := range upstreams {
u := u // Closure
go func() {
if !exists(ctx, r, path) {
r = nil
if !exists(ctx, u, path) {
u = nil
}
ch <- r
ch <- u
}()
}
var r *upstream.Fs
var u *upstream.Fs
for i := 0; i < len(upstreams); i++ {
r = <- ch
if r != nil {
u = <- ch
if u != nil {
// close remaining goroutines
go func(num int) {
defer close(ch)
@ -39,10 +39,10 @@ func (p *EpFF) epff(ctx context.Context, upstreams []*upstream.Fs, path string)
}(len(upstreams) - 1 - i)
}
}
if r == nil {
if u == nil {
return nil, fs.ErrorObjectNotFound
}
return r, nil
return u, nil
}
// 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 {
return nil, fs.ErrorPermissionDenied
}
r, err := p.epff(ctx, upstreams, path)
return []*upstream.Fs{r}, err
u, err := p.epff(ctx, upstreams, path)
return []*upstream.Fs{u}, err
}
// 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 {
return nil, fs.ErrorPermissionDenied
}
r, err := p.epff(ctx, upstreams, path)
return []*upstream.Fs{r}, err
u, err := p.epff(ctx, upstreams, path)
return []*upstream.Fs{u}, err
}
// CreateEntries is CREATE category policy but receving a set of candidate entries

View File

@ -12,7 +12,7 @@ func init(){
}
// 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 {
EpAll
}
@ -20,16 +20,19 @@ type EpMfs struct {
func (p *EpMfs) mfs(upstreams []*upstream.Fs) (*upstream.Fs, error) {
var maxFreeSpace int64
var mfsupstream *upstream.Fs
for _, r := range upstreams {
space, err := r.GetFreeSpace()
for _, u := range upstreams {
space, err := u.GetFreeSpace()
if err != nil {
return nil, err
}
if maxFreeSpace < space {
maxFreeSpace = space
mfsupstream = r
mfsupstream = u
}
}
if mfsupstream == nil {
return nil, fs.ErrorObjectNotFound
}
return mfsupstream, nil
}
@ -55,8 +58,8 @@ func (p *EpMfs) Action(ctx context.Context, upstreams []*upstream.Fs, path strin
if err != nil {
return nil, err
}
r, err := p.mfs(upstreams)
return []*upstream.Fs{r}, err
u, err := p.mfs(upstreams)
return []*upstream.Fs{u}, err
}
// 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 {
return nil, err
}
r, err := p.mfs(upstreams)
return []*upstream.Fs{r}, err
u, err := p.mfs(upstreams)
return []*upstream.Fs{u}, err
}
// CreateEntries is CREATE category policy but receving a set of candidate entries

View File

@ -12,7 +12,9 @@ func init(){
}
// 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 {
EpMfs
}
@ -26,6 +28,6 @@ func (p *Mfs) Create(ctx context.Context, upstreams []*upstream.Fs, path string)
if len(upstreams) == 0 {
return nil, fs.ErrorPermissionDenied
}
r, err := p.mfs(upstreams)
return []*upstream.Fs{r}, err
u, err := p.mfs(upstreams)
return []*upstream.Fs{u}, err
}