add hidden force-delete option (#4097)
This commit is contained in:
+1
-1
@@ -493,7 +493,7 @@ func deleteFile(basePath, deletePath string) error {
|
||||
}
|
||||
|
||||
// Remove - remove entry read from clientContent channel.
|
||||
func (f *fsClient) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) <-chan RemoveResult {
|
||||
func (f *fsClient) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass, isForceDel bool, contentCh <-chan *ClientContent) <-chan RemoveResult {
|
||||
resultCh := make(chan RemoveResult)
|
||||
|
||||
// Goroutine reads from contentCh and removes the entry in content.
|
||||
|
||||
+24
-5
@@ -1116,7 +1116,7 @@ type RemoveResult struct {
|
||||
}
|
||||
|
||||
// Remove - remove object or bucket(s).
|
||||
func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) <-chan RemoveResult {
|
||||
func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass, isForceDel bool, contentCh <-chan *ClientContent) <-chan RemoveResult {
|
||||
resultCh := make(chan RemoveResult)
|
||||
|
||||
prevBucket := ""
|
||||
@@ -1130,6 +1130,25 @@ func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB
|
||||
go func() {
|
||||
defer close(resultCh)
|
||||
|
||||
if isForceDel {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if e := c.api.RemoveObject(ctx, bucket, object, minio.RemoveObjectOptions{
|
||||
ForceDelete: isForceDel,
|
||||
}); e != nil {
|
||||
resultCh <- RemoveResult{
|
||||
Err: probe.NewError(e),
|
||||
}
|
||||
return
|
||||
}
|
||||
resultCh <- RemoveResult{
|
||||
BucketName: bucket,
|
||||
RemoveObjectResult: minio.RemoveObjectResult{
|
||||
ObjectName: object,
|
||||
},
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
_, object := c.url2BucketAndObject()
|
||||
if isRemoveBucket && object != "" {
|
||||
resultCh <- RemoveResult{
|
||||
@@ -1195,10 +1214,10 @@ func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB
|
||||
|
||||
// Remove bucket if it qualifies.
|
||||
if isRemoveBucket && !isIncomplete {
|
||||
if err := c.api.RemoveBucket(ctx, prevBucket); err != nil {
|
||||
if e := c.api.RemoveBucket(ctx, prevBucket); e != nil {
|
||||
resultCh <- RemoveResult{
|
||||
BucketName: bucket,
|
||||
Err: probe.NewError(err),
|
||||
Err: probe.NewError(e),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1280,10 +1299,10 @@ func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB
|
||||
}
|
||||
// Remove last bucket if it qualifies.
|
||||
if isRemoveBucket && prevBucket != "" && !isIncomplete {
|
||||
if err := c.api.RemoveBucket(ctx, prevBucket); err != nil {
|
||||
if e := c.api.RemoveBucket(ctx, prevBucket); e != nil {
|
||||
resultCh <- RemoveResult{
|
||||
BucketName: prevBucket,
|
||||
Err: probe.NewError(err),
|
||||
Err: probe.NewError(e),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
+1
-1
@@ -138,7 +138,7 @@ type Client interface {
|
||||
Watch(ctx context.Context, options WatchOptions) (*WatchObject, *probe.Error)
|
||||
|
||||
// Delete operations
|
||||
Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) (errorCh <-chan RemoveResult)
|
||||
Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass, isForceDel bool, contentCh <-chan *ClientContent) (errorCh <-chan RemoveResult)
|
||||
// GetURL returns back internal url
|
||||
GetURL() ClientURL
|
||||
AddUserAgent(app, version string)
|
||||
|
||||
+2
-2
@@ -318,7 +318,7 @@ func (mj *mirrorJob) doDeleteBucket(ctx context.Context, sURLs URLs) URLs {
|
||||
contentCh <- &ClientContent{URL: clnt.GetURL()}
|
||||
close(contentCh)
|
||||
|
||||
for result := range clnt.Remove(ctx, false, true, false, contentCh) {
|
||||
for result := range clnt.Remove(ctx, false, true, false, false, contentCh) {
|
||||
if result.Err != nil {
|
||||
return sURLs.WithError(result.Err)
|
||||
}
|
||||
@@ -348,7 +348,7 @@ func (mj *mirrorJob) doRemove(ctx context.Context, sURLs URLs) URLs {
|
||||
contentCh <- &ClientContent{URL: *newClientURL(sURLs.TargetContent.URL.Path)}
|
||||
close(contentCh)
|
||||
isRemoveBucket := false
|
||||
resultCh := clnt.Remove(ctx, false, isRemoveBucket, false, contentCh)
|
||||
resultCh := clnt.Remove(ctx, false, isRemoveBucket, false, false, contentCh)
|
||||
for result := range resultCh {
|
||||
if result.Err != nil {
|
||||
switch result.Err.ToGoError().(type) {
|
||||
|
||||
+1
-1
@@ -181,7 +181,7 @@ func (rm *removeManager) add(ctx context.Context, targetAlias, targetURL string)
|
||||
}
|
||||
|
||||
contentCh := make(chan *ClientContent, 10000)
|
||||
resultCh := client.Remove(ctx, false, false, false, contentCh)
|
||||
resultCh := client.Remove(ctx, false, false, false, false, contentCh)
|
||||
rm.readErrors(resultCh, targetURL)
|
||||
|
||||
clientInfo = &removeClientInfo{
|
||||
|
||||
+1
-1
@@ -157,7 +157,7 @@ func deleteBucket(ctx context.Context, url string, isForce bool) *probe.Error {
|
||||
return pErr
|
||||
}
|
||||
contentCh := make(chan *ClientContent)
|
||||
resultCh := clnt.Remove(ctx, false, false, false, contentCh)
|
||||
resultCh := clnt.Remove(ctx, false, false, false, false, contentCh)
|
||||
|
||||
go func() {
|
||||
defer close(contentCh)
|
||||
|
||||
+46
-10
@@ -96,6 +96,11 @@ var (
|
||||
Name: "non-current",
|
||||
Usage: "remove object(s) versions that are non-current",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "force-delete",
|
||||
Usage: "attempt a prefix force delete, requires confirmation please use with caution",
|
||||
Hidden: true,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -203,6 +208,7 @@ func checkRmSyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[string
|
||||
isDangerous := cliCtx.Bool("dangerous")
|
||||
isVersions := cliCtx.Bool("versions")
|
||||
isNoncurrentVersion := cliCtx.Bool("non-current")
|
||||
isForceDel := cliCtx.Bool("force-delete")
|
||||
versionID := cliCtx.String("version-id")
|
||||
rewind := cliCtx.String("rewind")
|
||||
isNamespaceRemoval := false
|
||||
@@ -217,6 +223,16 @@ func checkRmSyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[string
|
||||
"You cannot specify --non-current without --versions --recursive, please use --non-current --versions --recursive.")
|
||||
}
|
||||
|
||||
if isForceDel && !isForce {
|
||||
fatalIf(errDummy().Trace(),
|
||||
"You cannot specify --force-delete without --force.")
|
||||
}
|
||||
|
||||
if isForceDel && isRecursive {
|
||||
fatalIf(errDummy().Trace(),
|
||||
"You cannot specify --force-delete with --recursive.")
|
||||
}
|
||||
|
||||
for _, url := range cliCtx.Args() {
|
||||
// clean path for aliases like s3/.
|
||||
// Note: UNC path using / works properly in go 1.9.2 even though it breaks the UNC specification.
|
||||
@@ -255,7 +271,7 @@ func checkRmSyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[string
|
||||
}
|
||||
|
||||
// Remove a single object or a single version in a versioned bucket
|
||||
func removeSingle(url, versionID string, isIncomplete, isFake, isForce, isBypass bool, olderThan, newerThan string, encKeyDB map[string][]prefixSSEPair) error {
|
||||
func removeSingle(url, versionID string, opts removeOpts) error {
|
||||
ctx, cancel := context.WithCancel(globalContext)
|
||||
defer cancel()
|
||||
|
||||
@@ -271,7 +287,7 @@ func removeSingle(url, versionID string, isIncomplete, isFake, isForce, isBypass
|
||||
modTime time.Time
|
||||
)
|
||||
|
||||
_, content, pErr := url2Stat(ctx, url, versionID, false, encKeyDB, time.Time{}, false)
|
||||
_, content, pErr := url2Stat(ctx, url, versionID, false, opts.encKeyDB, time.Time{}, false)
|
||||
if pErr != nil {
|
||||
switch minio.ToErrorResponse(pErr.ToGoError()).StatusCode {
|
||||
case http.StatusBadRequest, http.StatusMethodNotAllowed:
|
||||
@@ -286,22 +302,22 @@ func removeSingle(url, versionID string, isIncomplete, isFake, isForce, isBypass
|
||||
}
|
||||
|
||||
// We should not proceed
|
||||
if ignoreStatError && olderThan != "" || newerThan != "" {
|
||||
if ignoreStatError && opts.olderThan != "" || opts.newerThan != "" {
|
||||
errorIf(pErr.Trace(url), "Unable to stat `"+url+"`.")
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
}
|
||||
|
||||
// Skip objects older than older--than parameter if specified
|
||||
if olderThan != "" && isOlder(modTime, olderThan) {
|
||||
if opts.olderThan != "" && isOlder(modTime, opts.olderThan) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Skip objects older than older--than parameter if specified
|
||||
if newerThan != "" && isNewer(modTime, newerThan) {
|
||||
if opts.newerThan != "" && isNewer(modTime, opts.newerThan) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !isFake {
|
||||
if !opts.isFake {
|
||||
targetAlias, targetURL, _ := mustExpandAlias(url)
|
||||
clnt, pErr := newClientFromAlias(targetAlias, targetURL)
|
||||
if pErr != nil {
|
||||
@@ -318,7 +334,7 @@ func removeSingle(url, versionID string, isIncomplete, isFake, isForce, isBypass
|
||||
contentCh <- &ClientContent{URL: contentURL, VersionID: versionID}
|
||||
close(contentCh)
|
||||
isRemoveBucket := false
|
||||
resultCh := clnt.Remove(ctx, isIncomplete, isRemoveBucket, isBypass, contentCh)
|
||||
resultCh := clnt.Remove(ctx, opts.isIncomplete, isRemoveBucket, opts.isBypass, opts.isForce && opts.isForceDel, contentCh)
|
||||
for result := range resultCh {
|
||||
if result.Err != nil {
|
||||
errorIf(result.Err.Trace(url), "Failed to remove `"+url+"`.")
|
||||
@@ -352,6 +368,7 @@ type removeOpts struct {
|
||||
isIncomplete bool
|
||||
isFake bool
|
||||
isBypass bool
|
||||
isForceDel bool
|
||||
olderThan string
|
||||
newerThan string
|
||||
encKeyDB map[string][]prefixSSEPair
|
||||
@@ -393,7 +410,7 @@ func listAndRemove(url string, opts removeOpts) error {
|
||||
}
|
||||
atLeastOneObjectFound := false
|
||||
|
||||
resultCh := clnt.Remove(ctx, opts.isIncomplete, isRemoveBucket, opts.isBypass, contentCh)
|
||||
resultCh := clnt.Remove(ctx, opts.isIncomplete, isRemoveBucket, opts.isBypass, false, contentCh)
|
||||
|
||||
var lastPath string
|
||||
var perObjectVersions []*ClientContent
|
||||
@@ -660,6 +677,7 @@ func mainRm(cliCtx *cli.Context) error {
|
||||
olderThan := cliCtx.String("older-than")
|
||||
newerThan := cliCtx.String("newer-than")
|
||||
isForce := cliCtx.Bool("force")
|
||||
isForceDel := cliCtx.Bool("force-delete")
|
||||
withNoncurrentVersion := cliCtx.Bool("non-current")
|
||||
withVersions := cliCtx.Bool("versions")
|
||||
versionID := cliCtx.String("version-id")
|
||||
@@ -691,7 +709,16 @@ func mainRm(cliCtx *cli.Context) error {
|
||||
encKeyDB: encKeyDB,
|
||||
})
|
||||
} else {
|
||||
e = removeSingle(url, versionID, isIncomplete, isFake, isForce, isBypass, olderThan, newerThan, encKeyDB)
|
||||
e = removeSingle(url, versionID, removeOpts{
|
||||
isIncomplete: isIncomplete,
|
||||
isFake: isFake,
|
||||
isForce: isForce,
|
||||
isForceDel: isForceDel,
|
||||
isBypass: isBypass,
|
||||
olderThan: olderThan,
|
||||
newerThan: newerThan,
|
||||
encKeyDB: encKeyDB,
|
||||
})
|
||||
}
|
||||
if rerr == nil {
|
||||
rerr = e
|
||||
@@ -720,7 +747,16 @@ func mainRm(cliCtx *cli.Context) error {
|
||||
encKeyDB: encKeyDB,
|
||||
})
|
||||
} else {
|
||||
e = removeSingle(url, versionID, isIncomplete, isFake, isForce, isBypass, olderThan, newerThan, encKeyDB)
|
||||
e = removeSingle(url, versionID, removeOpts{
|
||||
isIncomplete: isIncomplete,
|
||||
isFake: isFake,
|
||||
isForce: isForce,
|
||||
isForceDel: isForceDel,
|
||||
isBypass: isBypass,
|
||||
olderThan: olderThan,
|
||||
newerThan: newerThan,
|
||||
encKeyDB: encKeyDB,
|
||||
})
|
||||
}
|
||||
if rerr == nil {
|
||||
rerr = e
|
||||
|
||||
+1
-1
@@ -142,7 +142,7 @@ func undoLastNOperations(ctx context.Context, clnt Client, objectVersions []*Cli
|
||||
}
|
||||
|
||||
contentCh := make(chan *ClientContent)
|
||||
resultCh := clnt.Remove(ctx, false, false, false, contentCh)
|
||||
resultCh := clnt.Remove(ctx, false, false, false, false, contentCh)
|
||||
|
||||
prefixPath := clnt.GetURL().Path
|
||||
prefixPath = filepath.ToSlash(prefixPath)
|
||||
|
||||
Reference in New Issue
Block a user