mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
xl: Avoid removing a directory if it is not an object dir (#6395)
DeleteObject should not remove any directory unless the latter is an empty directory. Fixes #6394
This commit is contained in:
parent
4487f70f08
commit
85117d554f
@ -843,24 +843,27 @@ func (xl xlObjects) DeleteObject(ctx context.Context, bucket, object string) (er
|
||||
return err
|
||||
}
|
||||
|
||||
if hasSuffix(object, slashSeparator) {
|
||||
// Delete the object on all disks.
|
||||
if err = xl.deleteObject(ctx, bucket, object, len(xl.getDisks())/2+1, true); err != nil {
|
||||
if !xl.isObject(bucket, object) {
|
||||
return ObjectNotFound{bucket, object}
|
||||
}
|
||||
|
||||
var writeQuorum int
|
||||
var isObjectDir = hasSuffix(object, slashSeparator)
|
||||
|
||||
if isObjectDir {
|
||||
writeQuorum = len(xl.getDisks())/2 + 1
|
||||
} else {
|
||||
// Read metadata associated with the object from all disks.
|
||||
partsMetadata, errs := readAllXLMetadata(ctx, xl.getDisks(), bucket, object)
|
||||
// get Quorum for this object
|
||||
_, writeQuorum, err = objectQuorumFromMeta(ctx, xl, partsMetadata, errs)
|
||||
if err != nil {
|
||||
return toObjectErr(err, bucket, object)
|
||||
}
|
||||
}
|
||||
|
||||
// Read metadata associated with the object from all disks.
|
||||
partsMetadata, errs := readAllXLMetadata(ctx, xl.getDisks(), bucket, object)
|
||||
|
||||
// get Quorum for this object
|
||||
_, writeQuorum, err := objectQuorumFromMeta(ctx, xl, partsMetadata, errs)
|
||||
if err != nil {
|
||||
return toObjectErr(err, bucket, object)
|
||||
}
|
||||
|
||||
// Delete the object on all disks.
|
||||
if err = xl.deleteObject(ctx, bucket, object, writeQuorum, false); err != nil {
|
||||
if err = xl.deleteObject(ctx, bucket, object, writeQuorum, isObjectDir); err != nil {
|
||||
return toObjectErr(err, bucket, object)
|
||||
}
|
||||
|
||||
|
@ -71,11 +71,14 @@ func TestXLDeleteObjectBasic(t *testing.T) {
|
||||
object string
|
||||
expectedErr error
|
||||
}{
|
||||
{".test", "obj", BucketNameInvalid{Bucket: ".test"}},
|
||||
{"----", "obj", BucketNameInvalid{Bucket: "----"}},
|
||||
{".test", "dir/obj", BucketNameInvalid{Bucket: ".test"}},
|
||||
{"----", "dir/obj", BucketNameInvalid{Bucket: "----"}},
|
||||
{"bucket", "", ObjectNameInvalid{Bucket: "bucket", Object: ""}},
|
||||
{"bucket", "doesnotexist", ObjectNotFound{Bucket: "bucket", Object: "doesnotexist"}},
|
||||
{"bucket", "obj", nil},
|
||||
{"bucket", "dir/doesnotexist", ObjectNotFound{Bucket: "bucket", Object: "dir/doesnotexist"}},
|
||||
{"bucket", "dir", ObjectNotFound{Bucket: "bucket", Object: "dir"}},
|
||||
{"bucket", "dir/", ObjectNotFound{Bucket: "bucket", Object: "dir/"}},
|
||||
{"bucket", "dir/obj", nil},
|
||||
}
|
||||
|
||||
// Create an instance of xl backend
|
||||
@ -84,14 +87,13 @@ func TestXLDeleteObjectBasic(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Make bucket for Test 7 to pass
|
||||
err = xl.MakeBucketWithLocation(context.Background(), "bucket", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Create object "obj" under bucket "bucket" for Test 7 to pass
|
||||
_, err = xl.PutObject(context.Background(), "bucket", "obj", mustGetHashReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), nil)
|
||||
// Create object "dir/obj" under bucket "bucket" for Test 7 to pass
|
||||
_, err = xl.PutObject(context.Background(), "bucket", "dir/obj", mustGetHashReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("XL Object upload failed: <ERROR> %s", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user