mirror of
https://github.com/distribution/distribution.git
synced 2025-08-19 23:38:13 +00:00
storagedriver/s3: Fixed a case where Delete was not working when the subpath immediately followed the given path with a "-" and quit early with noop
This commit is contained in:
parent
1e3b6b67a8
commit
5d8fa0ce94
@ -958,7 +958,21 @@ func min(a, b int) int {
|
||||
// We must be careful since S3 does not guarantee read after delete consistency
|
||||
func (d *driver) Delete(ctx context.Context, path string) error {
|
||||
s3Objects := make([]*s3.ObjectIdentifier, 0, listMax)
|
||||
s3Path := d.s3Path(path)
|
||||
|
||||
// manually add the given path if it's a file
|
||||
stat, err := d.Stat(ctx, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if stat != nil && !stat.IsDir() {
|
||||
path := d.s3Path(path)
|
||||
s3Objects = append(s3Objects, &s3.ObjectIdentifier{
|
||||
Key: &path,
|
||||
})
|
||||
}
|
||||
|
||||
// list objects under the given path as a subpath (suffix with slash "/")
|
||||
s3Path := d.s3Path(path) + "/"
|
||||
listObjectsInput := &s3.ListObjectsInput{
|
||||
Bucket: aws.String(d.Bucket),
|
||||
Prefix: aws.String(s3Path),
|
||||
@ -974,14 +988,10 @@ ListLoop:
|
||||
// if there were no more results to return after the first call, resp.IsTruncated would have been false
|
||||
// and the loop would be exited without recalling ListObjects
|
||||
if err != nil || len(resp.Contents) == 0 {
|
||||
return storagedriver.PathNotFoundError{Path: path}
|
||||
break ListLoop
|
||||
}
|
||||
|
||||
for _, key := range resp.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)] != '/' {
|
||||
break ListLoop
|
||||
}
|
||||
s3Objects = append(s3Objects, &s3.ObjectIdentifier{
|
||||
Key: key.Key,
|
||||
})
|
||||
@ -997,8 +1007,12 @@ ListLoop:
|
||||
}
|
||||
}
|
||||
|
||||
// need to chunk objects into groups of 1000 per s3 restrictions
|
||||
total := len(s3Objects)
|
||||
if total == 0 {
|
||||
return storagedriver.PathNotFoundError{Path: path}
|
||||
}
|
||||
|
||||
// need to chunk objects into groups of 1000 per s3 restrictions
|
||||
for i := 0; i < total; i += 1000 {
|
||||
_, err := s.DeleteObjects(&s3.DeleteObjectsInput{
|
||||
Bucket: aws.String(d.Bucket),
|
||||
|
Loading…
Reference in New Issue
Block a user