Merge pull request #2005 from RichardScothern/nwt-fix-s3-goamz-delete
Nwt fix s3 goamz & Aliyun OSS delete
This commit is contained in:
commit
b6e8a3f441
2 changed files with 26 additions and 4 deletions
|
@ -408,7 +408,8 @@ func (d *driver) Move(ctx context.Context, sourcePath string, destPath string) e
|
|||
|
||||
// Delete recursively deletes all objects stored at "path" and its subpaths.
|
||||
func (d *driver) Delete(ctx context.Context, path string) error {
|
||||
listResponse, err := d.Bucket.List(d.ossPath(path), "", "", listMax)
|
||||
ossPath := d.ossPath(path)
|
||||
listResponse, err := d.Bucket.List(ossPath, "", "", listMax)
|
||||
if err != nil || len(listResponse.Contents) == 0 {
|
||||
return storagedriver.PathNotFoundError{Path: path}
|
||||
}
|
||||
|
@ -416,15 +417,25 @@ func (d *driver) Delete(ctx context.Context, path string) error {
|
|||
ossObjects := make([]oss.Object, listMax)
|
||||
|
||||
for len(listResponse.Contents) > 0 {
|
||||
numOssObjects := len(listResponse.Contents)
|
||||
for index, key := range listResponse.Contents {
|
||||
// Stop if we encounter a key that is not a subpath (so that deleting "/a" does not delete "/ab").
|
||||
if len(key.Key) > len(ossPath) && (key.Key)[len(ossPath)] != '/' {
|
||||
numOssObjects = index
|
||||
break
|
||||
}
|
||||
ossObjects[index].Key = key.Key
|
||||
}
|
||||
|
||||
err := d.Bucket.DelMulti(oss.Delete{Quiet: false, Objects: ossObjects[0:len(listResponse.Contents)]})
|
||||
err := d.Bucket.DelMulti(oss.Delete{Quiet: false, Objects: ossObjects[0:numOssObjects]})
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if numOssObjects < len(listResponse.Contents) {
|
||||
return nil
|
||||
}
|
||||
|
||||
listResponse, err = d.Bucket.List(d.ossPath(path), "", "", listMax)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -479,7 +479,8 @@ func (d *driver) Move(ctx context.Context, sourcePath string, destPath string) e
|
|||
|
||||
// Delete recursively deletes all objects stored at "path" and its subpaths.
|
||||
func (d *driver) Delete(ctx context.Context, path string) error {
|
||||
listResponse, err := d.Bucket.List(d.s3Path(path), "", "", listMax)
|
||||
s3Path := d.s3Path(path)
|
||||
listResponse, err := d.Bucket.List(s3Path, "", "", listMax)
|
||||
if err != nil || len(listResponse.Contents) == 0 {
|
||||
return storagedriver.PathNotFoundError{Path: path}
|
||||
}
|
||||
|
@ -487,15 +488,25 @@ func (d *driver) Delete(ctx context.Context, path string) error {
|
|||
s3Objects := make([]s3.Object, listMax)
|
||||
|
||||
for len(listResponse.Contents) > 0 {
|
||||
numS3Objects := len(listResponse.Contents)
|
||||
for index, key := range listResponse.Contents {
|
||||
// Stop if we encounter a key that is not a subpath (so that deleting "/a" does not delete "/ab").
|
||||
if len(key.Key) > len(s3Path) && (key.Key)[len(s3Path)] != '/' {
|
||||
numS3Objects = index
|
||||
break
|
||||
}
|
||||
s3Objects[index].Key = key.Key
|
||||
}
|
||||
|
||||
err := d.Bucket.DelMulti(s3.Delete{Quiet: false, Objects: s3Objects[0:len(listResponse.Contents)]})
|
||||
err := d.Bucket.DelMulti(s3.Delete{Quiet: false, Objects: s3Objects[0:numS3Objects]})
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if numS3Objects < len(listResponse.Contents) {
|
||||
return nil
|
||||
}
|
||||
|
||||
listResponse, err = d.Bucket.List(d.s3Path(path), "", "", listMax)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue