mirror of
https://github.com/rclone/rclone.git
synced 2025-03-01 00:42:36 +01:00
union: goimports fix
This commit is contained in:
parent
05666e6e51
commit
998169fc02
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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{})
|
||||
}
|
||||
|
||||
|
@ -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{})
|
||||
}
|
||||
|
||||
|
@ -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{})
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user