1
mirror of https://github.com/rclone/rclone synced 2025-04-10 05:02:09 +02:00

azureblob,b2,gcs,qingstor,s3,swift: Don't check for bucket/container presense if listing was OK

In a typical rclone copy to a bucket/container based remote, before
this change we were doing a list, followed by a HEAD of the bucket to
check it existed before doing the copy.  The fact the list succeeded
means the bucket exists so mark it OK at that point.

Issue 
This commit is contained in:
Nick Craig-Wood 2018-03-01 12:11:34 +00:00
parent 3f9d0d3baf
commit f3e982d3bf
6 changed files with 81 additions and 0 deletions
backend
azureblob
b2
googlecloudstorage
qingstor
s3
swift

@ -405,6 +405,16 @@ func (f *Fs) itemToDirEntry(remote string, object *storage.Blob, isDirectory boo
return o, nil return o, nil
} }
// mark the container as being OK
func (f *Fs) markContainerOK() {
if f.container != "" {
f.containerOKMu.Lock()
f.containerOK = true
f.containerDeleted = false
f.containerOKMu.Unlock()
}
}
// listDir lists a single directory // listDir lists a single directory
func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) { func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
err = f.list(dir, false, listChunkSize, func(remote string, object *storage.Blob, isDirectory bool) error { err = f.list(dir, false, listChunkSize, func(remote string, object *storage.Blob, isDirectory bool) error {
@ -420,6 +430,8 @@ func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// container must be present if listing succeeded
f.markContainerOK()
return entries, nil return entries, nil
} }
@ -491,6 +503,8 @@ func (f *Fs) ListR(dir string, callback fs.ListRCallback) (err error) {
if err != nil { if err != nil {
return err return err
} }
// container must be present if listing succeeded
f.markContainerOK()
return list.Flush() return list.Flush()
} }

@ -551,6 +551,15 @@ func (f *Fs) itemToDirEntry(remote string, object *api.File, isDirectory bool, l
return o, nil return o, nil
} }
// mark the bucket as being OK
func (f *Fs) markBucketOK() {
if f.bucket != "" {
f.bucketOKMu.Lock()
f.bucketOK = true
f.bucketOKMu.Unlock()
}
}
// listDir lists a single directory // listDir lists a single directory
func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) { func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
last := "" last := ""
@ -567,6 +576,8 @@ func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// bucket must be present if listing succeeded
f.markBucketOK()
return entries, nil return entries, nil
} }
@ -634,6 +645,8 @@ func (f *Fs) ListR(dir string, callback fs.ListRCallback) (err error) {
if err != nil { if err != nil {
return err return err
} }
// bucket must be present if listing succeeded
f.markBucketOK()
return list.Flush() return list.Flush()
} }

@ -463,6 +463,15 @@ func (f *Fs) itemToDirEntry(remote string, object *storage.Object, isDirectory b
return o, nil return o, nil
} }
// mark the bucket as being OK
func (f *Fs) markBucketOK() {
if f.bucket != "" {
f.bucketOKMu.Lock()
f.bucketOK = true
f.bucketOKMu.Unlock()
}
}
// listDir lists a single directory // listDir lists a single directory
func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) { func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
// List the objects // List the objects
@ -479,6 +488,8 @@ func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// bucket must be present if listing succeeded
f.markBucketOK()
return entries, err return entries, err
} }
@ -555,6 +566,8 @@ func (f *Fs) ListR(dir string, callback fs.ListRCallback) (err error) {
if err != nil { if err != nil {
return err return err
} }
// bucket must be present if listing succeeded
f.markBucketOK()
return list.Flush() return list.Flush()
} }

@ -519,6 +519,16 @@ func (f *Fs) itemToDirEntry(remote string, object *qs.KeyType, isDirectory bool)
return o, nil return o, nil
} }
// mark the bucket as being OK
func (f *Fs) markBucketOK() {
if f.bucket != "" {
f.bucketOKMu.Lock()
f.bucketOK = true
f.bucketDeleted = false
f.bucketOKMu.Unlock()
}
}
// listDir lists files and directories to out // listDir lists files and directories to out
func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) { func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
// List the objects and directories // List the objects and directories
@ -535,6 +545,8 @@ func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// bucket must be present if listing succeeded
f.markBucketOK()
return entries, nil return entries, nil
} }
@ -606,6 +618,8 @@ func (f *Fs) ListR(dir string, callback fs.ListRCallback) (err error) {
if err != nil { if err != nil {
return err return err
} }
// bucket must be present if listing succeeded
f.markBucketOK()
return list.Flush() return list.Flush()
} }

@ -590,6 +590,16 @@ func (f *Fs) itemToDirEntry(remote string, object *s3.Object, isDirectory bool)
return o, nil return o, nil
} }
// mark the bucket as being OK
func (f *Fs) markBucketOK() {
if f.bucket != "" {
f.bucketOKMu.Lock()
f.bucketOK = true
f.bucketDeleted = false
f.bucketOKMu.Unlock()
}
}
// listDir lists files and directories to out // listDir lists files and directories to out
func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) { func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
// List the objects and directories // List the objects and directories
@ -606,6 +616,8 @@ func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// bucket must be present if listing succeeded
f.markBucketOK()
return entries, nil return entries, nil
} }
@ -673,6 +685,8 @@ func (f *Fs) ListR(dir string, callback fs.ListRCallback) (err error) {
if err != nil { if err != nil {
return err return err
} }
// bucket must be present if listing succeeded
f.markBucketOK()
return list.Flush() return list.Flush()
} }

@ -407,6 +407,15 @@ func (f *Fs) list(dir string, recurse bool, fn addEntryFn) error {
return err return err
} }
// mark the container as being OK
func (f *Fs) markContainerOK() {
if f.container != "" {
f.containerOKMu.Lock()
f.containerOK = true
f.containerOKMu.Unlock()
}
}
// listDir lists a single directory // listDir lists a single directory
func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) { func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
if f.container == "" { if f.container == "" {
@ -420,6 +429,8 @@ func (f *Fs) listDir(dir string) (entries fs.DirEntries, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// container must be present if listing succeeded
f.markContainerOK()
return entries, nil return entries, nil
} }
@ -482,6 +493,8 @@ func (f *Fs) ListR(dir string, callback fs.ListRCallback) (err error) {
if err != nil { if err != nil {
return err return err
} }
// container must be present if listing succeeded
f.markContainerOK()
return list.Flush() return list.Flush()
} }