diff --git a/backend/union/policy/all.go b/backend/union/policy/all.go index 42f7a263b..06589220d 100644 --- a/backend/union/policy/all.go +++ b/backend/union/policy/all.go @@ -2,12 +2,12 @@ package policy import ( "context" - - "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("all", &All{}) } @@ -41,4 +41,4 @@ func (p *All) CreateEntries(entries ...upstream.Entry) ([]upstream.Entry, error) return nil, fs.ErrorPermissionDenied } return entries, nil -} \ No newline at end of file +} diff --git a/backend/union/policy/epall.go b/backend/union/policy/epall.go index 03efc40e7..63b994b3f 100644 --- a/backend/union/policy/epall.go +++ b/backend/union/policy/epall.go @@ -3,12 +3,12 @@ package policy import ( "context" "sync" - - "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("epall", &EpAll{}) } @@ -93,4 +93,4 @@ func (p *EpAll) CreateEntries(entries ...upstream.Entry) ([]upstream.Entry, erro return nil, fs.ErrorPermissionDenied } return entries, nil -} \ No newline at end of file +} diff --git a/backend/union/policy/epff.go b/backend/union/policy/epff.go index 2efc424f3..b93afbc1b 100644 --- a/backend/union/policy/epff.go +++ b/backend/union/policy/epff.go @@ -2,18 +2,18 @@ package policy import ( "context" - - "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("epff", &EpFF{}) } // EpFF stands for existing path, first found // Given the order of the candidates, act on the first one found where the relative path exists. -type EpFF struct {} +type EpFF struct{} func (p *EpFF) epff(ctx context.Context, upstreams []*upstream.Fs, path string) (*upstream.Fs, error) { ch := make(chan *upstream.Fs) @@ -28,13 +28,13 @@ func (p *EpFF) epff(ctx context.Context, upstreams []*upstream.Fs, path string) } var u *upstream.Fs for i := 0; i < len(upstreams); i++ { - u = <- ch + u = <-ch if u != nil { // close remaining goroutines go func(num int) { defer close(ch) for i := 0; i < num; i++ { - <- ch + <-ch } }(len(upstreams) - 1 - i) } @@ -109,4 +109,4 @@ func (p *EpFF) SearchEntries(entries ...upstream.Entry) (upstream.Entry, error) return nil, fs.ErrorObjectNotFound } return entries[0], nil -} \ No newline at end of file +} diff --git a/backend/union/policy/eplfs.go b/backend/union/policy/eplfs.go index 6776fd8bf..454206b77 100644 --- a/backend/union/policy/eplfs.go +++ b/backend/union/policy/eplfs.go @@ -3,12 +3,12 @@ package policy import ( "context" "math" - - "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("eplfs", &EpLfs{}) } @@ -111,4 +111,4 @@ func (p *EpLfs) SearchEntries(entries ...upstream.Entry) (upstream.Entry, error) return nil, fs.ErrorObjectNotFound } return p.lfsEntries(entries) -} \ No newline at end of file +} diff --git a/backend/union/policy/eplus.go b/backend/union/policy/eplus.go index eca166940..e3aea8feb 100644 --- a/backend/union/policy/eplus.go +++ b/backend/union/policy/eplus.go @@ -3,12 +3,12 @@ package policy import ( "context" "math" - - "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("eplus", &EpLus{}) } @@ -111,4 +111,4 @@ func (p *EpLus) SearchEntries(entries ...upstream.Entry) (upstream.Entry, error) return nil, fs.ErrorObjectNotFound } return p.lusEntries(entries) -} \ No newline at end of file +} diff --git a/backend/union/policy/epmfs.go b/backend/union/policy/epmfs.go index c9e69ca1b..06b195047 100644 --- a/backend/union/policy/epmfs.go +++ b/backend/union/policy/epmfs.go @@ -2,12 +2,12 @@ package policy import ( "context" - - "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("epmfs", &EpMfs{}) } @@ -110,4 +110,4 @@ func (p *EpMfs) SearchEntries(entries ...upstream.Entry) (upstream.Entry, error) return nil, fs.ErrorObjectNotFound } return p.mfsEntries(entries) -} \ No newline at end of file +} diff --git a/backend/union/policy/eprand.go b/backend/union/policy/eprand.go index efecbb8f5..bc137ac78 100644 --- a/backend/union/policy/eprand.go +++ b/backend/union/policy/eprand.go @@ -4,12 +4,12 @@ import ( "context" "math/rand" "time" - - "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("eprand", &EpRand{}) } @@ -83,4 +83,4 @@ func (p *EpRand) SearchEntries(entries ...upstream.Entry) (upstream.Entry, error return nil, fs.ErrorObjectNotFound } return p.randEntries(entries), nil -} \ No newline at end of file +} diff --git a/backend/union/policy/ff.go b/backend/union/policy/ff.go index 87be6904a..280c81cc2 100644 --- a/backend/union/policy/ff.go +++ b/backend/union/policy/ff.go @@ -2,12 +2,12 @@ package policy import ( "context" - - "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("ff", &FF{}) } @@ -29,4 +29,4 @@ func (p *FF) Create(ctx context.Context, upstreams []*upstream.Fs, path string) return upstreams, fs.ErrorPermissionDenied } return upstreams[:1], nil -} \ No newline at end of file +} diff --git a/backend/union/policy/lfs.go b/backend/union/policy/lfs.go index 7e5cc99c2..972906ee1 100644 --- a/backend/union/policy/lfs.go +++ b/backend/union/policy/lfs.go @@ -3,11 +3,11 @@ package policy import ( "context" - "github.com/rclone/rclone/fs" "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("lfs", &Lfs{}) } diff --git a/backend/union/policy/lus.go b/backend/union/policy/lus.go index edb6cef48..ad9b3fc77 100644 --- a/backend/union/policy/lus.go +++ b/backend/union/policy/lus.go @@ -3,11 +3,11 @@ package policy import ( "context" - "github.com/rclone/rclone/fs" "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("lus", &Lus{}) } diff --git a/backend/union/policy/mfs.go b/backend/union/policy/mfs.go index bc4cca5d9..162545a97 100644 --- a/backend/union/policy/mfs.go +++ b/backend/union/policy/mfs.go @@ -3,11 +3,11 @@ package policy import ( "context" - "github.com/rclone/rclone/fs" "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("mfs", &Mfs{}) } diff --git a/backend/union/policy/newest.go b/backend/union/policy/newest.go index bb5425def..b380eaad4 100644 --- a/backend/union/policy/newest.go +++ b/backend/union/policy/newest.go @@ -5,11 +5,11 @@ import ( "sync" "time" - "github.com/rclone/rclone/fs" "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("newest", &Newest{}) } @@ -52,7 +52,7 @@ func (p *Newest) newest(ctx context.Context, upstreams []*upstream.Fs, path stri func (p *Newest) newestEntries(entries []upstream.Entry) (upstream.Entry, error) { var wg sync.WaitGroup mtimes := make([]time.Time, len(entries)) - ctx, _ := context.WithTimeout(context.Background(), 5 * time.Second) + ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) for i, e := range entries { wg.Add(1) i, e := i, e // Closure @@ -142,4 +142,4 @@ func (p *Newest) SearchEntries(entries ...upstream.Entry) (upstream.Entry, error return nil, fs.ErrorObjectNotFound } return p.newestEntries(entries) -} \ No newline at end of file +} diff --git a/backend/union/policy/policy.go b/backend/union/policy/policy.go index b31f0749b..0f3456374 100644 --- a/backend/union/policy/policy.go +++ b/backend/union/policy/policy.go @@ -2,15 +2,15 @@ package policy import ( "context" - "strings" "math/rand" "path" "path/filepath" + "strings" "time" "github.com/pkg/errors" - "github.com/rclone/rclone/fs" "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) var policies = make(map[string]Policy) @@ -105,13 +105,13 @@ func clean(absPath string) string { func findEntry(ctx context.Context, f fs.Fs, remote string) fs.DirEntry { remote = clean(remote) dir := parentDir(remote) - entries, err := f.List(ctx, dir); + entries, err := f.List(ctx, dir) if remote == dir { if err != nil { return nil } // random modtime for root - randomNow := time.Unix(time.Now().Unix() - rand.Int63n(10000), 0) + randomNow := time.Unix(time.Now().Unix()-rand.Int63n(10000), 0) return fs.NewDir("", randomNow) } found := false diff --git a/backend/union/policy/rand.go b/backend/union/policy/rand.go index c2b0f2a88..acea62af4 100644 --- a/backend/union/policy/rand.go +++ b/backend/union/policy/rand.go @@ -4,12 +4,12 @@ import ( "context" "math/rand" "time" - - "github.com/rclone/rclone/fs" + "github.com/rclone/rclone/backend/union/upstream" + "github.com/rclone/rclone/fs" ) -func init(){ +func init() { registerPolicy("rand", &Rand{}) } @@ -83,4 +83,4 @@ func (p *Rand) SearchEntries(entries ...upstream.Entry) (upstream.Entry, error) return nil, fs.ErrorObjectNotFound } return p.randEntries(entries), nil -} \ No newline at end of file +} diff --git a/backend/union/union.go b/backend/union/union.go index 4265b5c6e..85177ae30 100644 --- a/backend/union/union.go +++ b/backend/union/union.go @@ -1,8 +1,8 @@ package union import ( - "context" "bufio" + "context" "fmt" "io" "path" @@ -12,8 +12,8 @@ import ( "time" "github.com/pkg/errors" - "github.com/rclone/rclone/backend/union/upstream" "github.com/rclone/rclone/backend/union/policy" + "github.com/rclone/rclone/backend/union/upstream" "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/config/configmap" "github.com/rclone/rclone/fs/config/configstruct" @@ -66,15 +66,15 @@ type Options struct { // Fs represents a union of upstreams type Fs struct { - name string // name of this remote - features *fs.Features // optional features - opt Options // options for this Fs - root string // the path we are working on - upstreams []*upstream.Fs // slice of upstreams - hashSet hash.Set // intersection of hash types - actionPolicy policy.Policy // policy for ACTION - createPolicy policy.Policy // policy for CREATE - searchPolicy policy.Policy // policy for SEARCH + name string // name of this remote + features *fs.Features // optional features + opt Options // options for this Fs + root string // the path we are working on + upstreams []*upstream.Fs // slice of upstreams + hashSet hash.Set // intersection of hash types + actionPolicy policy.Policy // policy for ACTION + createPolicy policy.Policy // policy for CREATE + searchPolicy policy.Policy // policy for SEARCH } // Wrap candidate objects in to an union Object @@ -85,15 +85,15 @@ func (f *Fs) wrapEntries(entries ...upstream.Entry) (entry, error) { } switch e.(type) { case *upstream.Object: - return &Object { - Object: e.(*upstream.Object), - fs: f, - co: entries, + return &Object{ + Object: e.(*upstream.Object), + fs: f, + co: entries, }, nil case *upstream.Directory: - return &Directory { - Directory: e.(*upstream.Directory), - cd: entries, + return &Directory{ + Directory: e.(*upstream.Directory), + cd: entries, }, nil default: return nil, errors.Errorf("unknown object type %T", e) @@ -127,7 +127,7 @@ func (f *Fs) Rmdir(ctx context.Context, dir string) error { return err } errs := make([]error, len(upstreams)) - multithread(len(upstreams), func(i int){ + multithread(len(upstreams), func(i int) { errs[i] = upstreams[i].Rmdir(ctx, dir) }) for _, err := range errs { @@ -151,7 +151,7 @@ func (f *Fs) Mkdir(ctx context.Context, dir string) error { return err } errs := make([]error, len(upstreams)) - multithread(len(upstreams), func(i int){ + multithread(len(upstreams), func(i int) { errs[i] = upstreams[i].Mkdir(ctx, dir) }) for _, err := range errs { @@ -179,7 +179,7 @@ func (f *Fs) Purge(ctx context.Context) error { return err } errs := make([]error, len(upstreams)) - multithread(len(upstreams), func(i int){ + multithread(len(upstreams), func(i int) { errs[i] = upstreams[i].Features().Purge(ctx) }) for _, err := range errs { @@ -248,9 +248,9 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, } objs := make([]*upstream.Object, len(entries)) errs := make([]error, len(entries)) - multithread(len(entries), func(i int){ + multithread(len(entries), func(i int) { u := entries[i].UpstreamFs() - o, ok := entries[i].(*upstream.Object); + o, ok := entries[i].(*upstream.Object) if !ok { errs[i] = fs.ErrorNotAFile return @@ -304,7 +304,7 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string } } errs := make([]error, len(upstreams)) - multithread(len(upstreams), func(i int){ + multithread(len(upstreams), func(i int) { u := upstreams[i] errs[i] = u.Features().DirMove(ctx, u, srcRemote, dstRemote) }) @@ -351,7 +351,7 @@ func (f *Fs) ChangeNotify(ctx context.Context, fn func(string, fs.EntryType), ch // DirCacheFlush resets the directory cache - used in testing // as an optional interface func (f *Fs) DirCacheFlush() { - multithread(len(f.upstreams), func(i int){ + multithread(len(f.upstreams), func(i int) { if do := f.upstreams[i].Features().DirCacheFlush; do != nil { do() } @@ -515,7 +515,7 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) { func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error) { entriess := make([][]upstream.Entry, len(f.upstreams)) errs := make([]error, len(f.upstreams)) - multithread(len(f.upstreams), func(i int){ + multithread(len(f.upstreams), func(i int) { u := f.upstreams[i] entries, err := u.List(ctx, dir) if err != nil { @@ -548,7 +548,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) { objs := make([]*upstream.Object, len(f.upstreams)) errs := make([]error, len(f.upstreams)) - multithread(len(f.upstreams), func(i int){ + multithread(len(f.upstreams), func(i int) { u := f.upstreams[i] o, err := u.NewObject(ctx, remote) if err != nil && err != fs.ErrorObjectNotFound { @@ -664,7 +664,7 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) { errs := make([]error, len(opt.Upstreams)) multithread(len(opt.Upstreams), func(i int) { u := opt.Upstreams[i] - upstreams[i], errs[i] = upstream.New(u, root, time.Duration(opt.CacheTime) * time.Second) + upstreams[i], errs[i] = upstream.New(u, root, time.Duration(opt.CacheTime)*time.Second) }) var usedUpstreams []*upstream.Fs var fserr error @@ -683,10 +683,10 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) { } f := &Fs{ - name: name, - root: root, - opt: *opt, - upstreams: usedUpstreams, + name: name, + root: root, + opt: *opt, + upstreams: usedUpstreams, } f.actionPolicy, err = policy.Get(opt.ActionPolicy) if err != nil { diff --git a/backend/union/upstream/upstream.go b/backend/union/upstream/upstream.go index 03973ee1a..ada593179 100644 --- a/backend/union/upstream/upstream.go +++ b/backend/union/upstream/upstream.go @@ -32,9 +32,9 @@ type Fs struct { fs.Fs writable bool creatable bool - usage *fs.Usage // Cache the usage + usage *fs.Usage // Cache the usage cacheMutex sync.RWMutex - cacheExpiry int64 // usage cache expiry time + cacheExpiry int64 // usage cache expiry time cacheTime time.Duration // cache duration cacheState uint32 // if the cache is updating } @@ -302,7 +302,7 @@ func (f *Fs) updateUsageCore(lock bool) error { atomic.StoreInt64(&f.cacheExpiry, time.Now().Add(f.cacheTime).Unix()) atomic.StoreUint32(&f.cacheState, normal) }() - if (lock) { + if lock { f.cacheMutex.Lock() defer f.cacheMutex.Unlock() } @@ -314,4 +314,4 @@ func (f *Fs) updateUsageCore(lock bool) error { } f.usage = usage return nil -} \ No newline at end of file +}