Skip to content

Commit 1697c82

Browse files
authored
Fixed an issue while deleting objects with similar prefixes (#3035)
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent b378b8c commit 1697c82

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2023 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import * as roles from "../utils/roles";
18+
import { Selector } from "testcafe";
19+
import * as functions from "../utils/functions";
20+
import { namedTestBucketBrowseButtonFor } from "../utils/functions";
21+
22+
fixture("Test resources policy").page("http://localhost:9090/");
23+
24+
const bucket1 = "abucket3";
25+
const test1BucketBrowseButton = namedTestBucketBrowseButtonFor(bucket1);
26+
export const remainingFile = Selector(
27+
".ReactVirtualized__Table__rowColumn",
28+
).withText("abcd");
29+
30+
test
31+
.before(async (t) => {
32+
await functions.setUpNamedBucket(t, bucket1);
33+
await functions.setVersionedBucket(t, bucket1);
34+
await functions.uploadNamedObjectToBucket(
35+
t,
36+
bucket1,
37+
"abc",
38+
"portal-ui/tests/uploads/noextension",
39+
);
40+
await functions.uploadNamedObjectToBucket(
41+
t,
42+
bucket1,
43+
"abcd",
44+
"portal-ui/tests/uploads/noextension",
45+
);
46+
})(
47+
"Files with similar prefixes don't get deleted with all versions",
48+
async (t) => {
49+
await t
50+
.useRole(roles.admin)
51+
.navigateTo(`http://localhost:9090/browser`)
52+
.click(test1BucketBrowseButton)
53+
.click(Selector(".ReactVirtualized__Table__rowColumn").withText("abc"))
54+
.click(Selector("#delete-element-click"))
55+
.click(Selector("#delete-versions-switch"))
56+
.click(Selector("#confirm-ok"))
57+
.expect(remainingFile.exists)
58+
.ok();
59+
},
60+
)
61+
.after(async (t) => {
62+
await functions.cleanUpNamedBucketAndUploads(t, bucket1);
63+
});

portal-ui/tests/uploads/noextension

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a demo file

restapi/user_objects.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,17 +854,22 @@ func deleteObjects(ctx context.Context, client MCClient, bucket string, path str
854854
}
855855

856856
if recursive || allVersions {
857-
return deleteMultipleObjects(ctx, client, recursive, allVersions, bypass)
857+
return deleteMultipleObjects(ctx, client, path, recursive, allVersions, bypass)
858858
}
859859

860860
return deleteSingleObject(ctx, client, bucket, path, versionID, bypass)
861861
}
862862

863+
// Return standardized URL to be used to compare later.
864+
func getStandardizedURL(targetURL string) string {
865+
return filepath.FromSlash(targetURL)
866+
}
867+
863868
// deleteMultipleObjects uses listing before removal, it can list recursively or not,
864869
//
865870
// Use cases:
866871
// * Remove objects recursively
867-
func deleteMultipleObjects(ctx context.Context, client MCClient, recursive, allVersions, isBypass bool) error {
872+
func deleteMultipleObjects(ctx context.Context, client MCClient, path string, recursive, allVersions, isBypass bool) error {
868873
// Constants defined to make this code more readable
869874
const (
870875
isIncomplete = false
@@ -892,6 +897,11 @@ func deleteMultipleObjects(ctx context.Context, client MCClient, recursive, allV
892897
if content.Err != nil {
893898
continue
894899
}
900+
901+
if !strings.HasSuffix(getStandardizedURL(content.URL.Path), path) && !strings.HasSuffix(path, "/") {
902+
continue
903+
}
904+
895905
select {
896906
case contentCh <- content:
897907
case <-lctx.Done():

0 commit comments

Comments
 (0)