From 1f2429c33696b9c831766338f69ecf3a78d30b46 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Sinha Date: Thu, 16 Sep 2021 00:04:41 +0530 Subject: [PATCH] validation for namespace removal (#3783) --- cmd/rm-main.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cmd/rm-main.go b/cmd/rm-main.go index 9ed1ac81..e8a777ef 100644 --- a/cmd/rm-main.go +++ b/cmd/rm-main.go @@ -210,7 +210,7 @@ func checkRmSyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[string url = filepath.ToSlash(filepath.Clean(url)) // namespace removal applies only for non FS. So filter out if passed url represents a directory dir := isAliasURLDir(ctx, url, encKeyDB, time.Time{}) - if !dir { + if dir { _, path := url2Alias(url) isNamespaceRemoval = (path == "") break @@ -231,17 +231,15 @@ func checkRmSyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[string // For all recursive or versions bulk deletion operations make sure to check for 'force' flag. if (isVersions || isRecursive || isStdin) && !isForce { - if isNamespaceRemoval { - fatalIf(errDummy().Trace(), - "This operation results in site-wide removal of objects. If you are really sure, retry this command with ‘--dangerous’ and ‘--force’ flags.") - } fatalIf(errDummy().Trace(), "Removal requires --force flag. This operation is *IRREVERSIBLE*. Please review carefully before performing this *DANGEROUS* operation.") } - if (isRecursive || isStdin) && isNamespaceRemoval && !isDangerous { + + if isNamespaceRemoval && !(isDangerous && isForce) { fatalIf(errDummy().Trace(), "This operation results in site-wide removal of objects. If you are really sure, retry this command with ‘--dangerous’ and ‘--force’ flags.") } + } // Remove a single object or a single version in a versioned bucket