display when delete markers are created (#3904)
This commit is contained in:
+19
-7
@@ -474,16 +474,18 @@ func deleteFile(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 *probe.Error {
|
||||
errorCh := make(chan *probe.Error)
|
||||
func (f *fsClient) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) <-chan RemoveResult {
|
||||
resultCh := make(chan RemoveResult)
|
||||
|
||||
// Goroutine reads from contentCh and removes the entry in content.
|
||||
go func() {
|
||||
defer close(errorCh)
|
||||
defer close(resultCh)
|
||||
|
||||
for content := range contentCh {
|
||||
if content.Err != nil {
|
||||
errorCh <- content.Err
|
||||
resultCh <- RemoveResult{
|
||||
Err: content.Err,
|
||||
}
|
||||
continue
|
||||
}
|
||||
name := content.URL.Path
|
||||
@@ -493,6 +495,10 @@ func (f *fsClient) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB
|
||||
}
|
||||
e := deleteFile(name)
|
||||
if e == nil {
|
||||
_, objectName := url2BucketAndObject(&content.URL, false)
|
||||
res := RemoveResult{}
|
||||
res.ObjectName = objectName
|
||||
resultCh <- res
|
||||
continue
|
||||
}
|
||||
if os.IsNotExist(e) && isRemoveBucket {
|
||||
@@ -501,15 +507,21 @@ func (f *fsClient) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB
|
||||
}
|
||||
if os.IsPermission(e) {
|
||||
// Ignore permission error.
|
||||
errorCh <- probe.NewError(PathInsufficientPermission{Path: content.URL.Path})
|
||||
resultCh <- RemoveResult{
|
||||
Err: probe.NewError(PathInsufficientPermission{
|
||||
Path: content.URL.Path,
|
||||
}),
|
||||
}
|
||||
} else {
|
||||
errorCh <- probe.NewError(e)
|
||||
resultCh <- RemoveResult{
|
||||
Err: probe.NewError(e),
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return errorCh
|
||||
return resultCh
|
||||
}
|
||||
|
||||
// List - list files and folders.
|
||||
|
||||
+90
-40
@@ -1065,8 +1065,8 @@ func (c *S3Client) Put(ctx context.Context, reader io.Reader, size int64, progre
|
||||
}
|
||||
|
||||
// Remove incomplete uploads.
|
||||
func (c *S3Client) removeIncompleteObjects(ctx context.Context, bucket string, objectsCh <-chan minio.ObjectInfo) <-chan minio.RemoveObjectError {
|
||||
removeObjectErrorCh := make(chan minio.RemoveObjectError)
|
||||
func (c *S3Client) removeIncompleteObjects(ctx context.Context, bucket string, objectsCh <-chan minio.ObjectInfo) <-chan minio.RemoveObjectResult {
|
||||
removeObjectErrorCh := make(chan minio.RemoveObjectResult)
|
||||
|
||||
// Goroutine reads from objectsCh and sends error to removeObjectErrorCh if any.
|
||||
go func() {
|
||||
@@ -1074,7 +1074,7 @@ func (c *S3Client) removeIncompleteObjects(ctx context.Context, bucket string, o
|
||||
|
||||
for info := range objectsCh {
|
||||
if err := c.api.RemoveIncompleteUpload(ctx, bucket, info.Key); err != nil {
|
||||
removeObjectErrorCh <- minio.RemoveObjectError{ObjectName: info.Key, Err: err}
|
||||
removeObjectErrorCh <- minio.RemoveObjectResult{ObjectName: info.Key, Err: err}
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -1087,32 +1087,42 @@ func (c *S3Client) AddUserAgent(app string, version string) {
|
||||
c.api.SetAppInfo(app, version)
|
||||
}
|
||||
|
||||
// RemoveResult returns the error or result of the removed objects.
|
||||
type RemoveResult struct {
|
||||
minio.RemoveObjectResult
|
||||
Err *probe.Error
|
||||
}
|
||||
|
||||
// Remove - remove object or bucket(s).
|
||||
func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) <-chan *probe.Error {
|
||||
errorCh := make(chan *probe.Error)
|
||||
func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) <-chan RemoveResult {
|
||||
resultCh := make(chan RemoveResult)
|
||||
|
||||
prevBucket := ""
|
||||
// Maintain objectsCh, statusCh for each bucket
|
||||
var objectsCh chan minio.ObjectInfo
|
||||
var statusCh <-chan minio.RemoveObjectError
|
||||
var statusCh <-chan minio.RemoveObjectResult
|
||||
opts := minio.RemoveObjectsOptions{
|
||||
GovernanceBypass: isBypass,
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer close(errorCh)
|
||||
defer close(resultCh)
|
||||
if isRemoveBucket {
|
||||
if _, object := c.url2BucketAndObject(); object != "" {
|
||||
errorCh <- probe.NewError(errors.New(
|
||||
"use `mc rm` command to delete prefixes, or point your" +
|
||||
" bucket directly, `mc rb <alias>/<bucket-name>/`"))
|
||||
resultCh <- RemoveResult{
|
||||
Err: probe.NewError(errors.New(
|
||||
"use `mc rm` command to delete prefixes, or point your" +
|
||||
" bucket directly, `mc rb <alias>/<bucket-name>/`"),
|
||||
)}
|
||||
return
|
||||
}
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
errorCh <- probe.NewError(ctx.Err())
|
||||
resultCh <- RemoveResult{
|
||||
Err: probe.NewError(ctx.Err()),
|
||||
}
|
||||
return
|
||||
case content, ok := <-contentCh:
|
||||
if !ok {
|
||||
@@ -1136,7 +1146,7 @@ func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB
|
||||
if isIncomplete {
|
||||
statusCh = c.removeIncompleteObjects(ctx, bucket, objectsCh)
|
||||
} else {
|
||||
statusCh = c.api.RemoveObjects(ctx, bucket, objectsCh, opts)
|
||||
statusCh = c.api.RemoveObjectsWithResult(ctx, bucket, objectsCh, opts)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1144,13 +1154,26 @@ func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB
|
||||
if objectsCh != nil {
|
||||
close(objectsCh)
|
||||
}
|
||||
|
||||
for removeStatus := range statusCh {
|
||||
errorCh <- probe.NewError(removeStatus.Err)
|
||||
if removeStatus.Err != nil {
|
||||
resultCh <- RemoveResult{
|
||||
Err: probe.NewError(removeStatus.Err),
|
||||
}
|
||||
} else {
|
||||
resultCh <- RemoveResult{
|
||||
RemoveObjectResult: removeStatus,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove bucket if it qualifies.
|
||||
if isRemoveBucket && !isIncomplete {
|
||||
if err := c.api.RemoveBucket(ctx, prevBucket); err != nil {
|
||||
errorCh <- probe.NewError(err)
|
||||
resultCh <- RemoveResult{
|
||||
Err: probe.NewError(err),
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
// Re-init objectsCh for next bucket
|
||||
@@ -1158,7 +1181,7 @@ func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB
|
||||
if isIncomplete {
|
||||
statusCh = c.removeIncompleteObjects(ctx, bucket, objectsCh)
|
||||
} else {
|
||||
statusCh = c.api.RemoveObjects(ctx, bucket, objectsCh, opts)
|
||||
statusCh = c.api.RemoveObjectsWithResult(ctx, bucket, objectsCh, opts)
|
||||
}
|
||||
prevBucket = bucket
|
||||
}
|
||||
@@ -1170,10 +1193,21 @@ func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB
|
||||
sent := false
|
||||
for !sent {
|
||||
select {
|
||||
case objectsCh <- minio.ObjectInfo{Key: objectName, VersionID: objectVersionID}:
|
||||
case objectsCh <- minio.ObjectInfo{
|
||||
Key: objectName,
|
||||
VersionID: objectVersionID,
|
||||
}:
|
||||
sent = true
|
||||
case removeStatus := <-statusCh:
|
||||
errorCh <- probe.NewError(removeStatus.Err)
|
||||
if removeStatus.Err != nil {
|
||||
resultCh <- RemoveResult{
|
||||
Err: probe.NewError(removeStatus.Err),
|
||||
}
|
||||
} else {
|
||||
resultCh <- RemoveResult{
|
||||
RemoveObjectResult: removeStatus,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -1191,28 +1225,40 @@ func (c *S3Client) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB
|
||||
if objectsCh != nil {
|
||||
close(objectsCh)
|
||||
}
|
||||
// Write remove objects status to errorCh
|
||||
// Write remove objects status to resultCh
|
||||
if statusCh != nil {
|
||||
for removeStatus := range statusCh {
|
||||
// If the removeStatus error message is:
|
||||
// "Object is WORM protected and cannot be overwritten",
|
||||
// it is too generic. We have the object's name and vid.
|
||||
// Adding the object's name and version id into the error msg
|
||||
removeStatus.Err = errors.New(strings.Replace(
|
||||
removeStatus.Err.Error(), "Object is WORM protected",
|
||||
"Object, '"+removeStatus.ObjectName+" (Version ID="+
|
||||
removeStatus.VersionID+")' is WORM protected", 1))
|
||||
errorCh <- probe.NewError(removeStatus.Err)
|
||||
if removeStatus.Err != nil {
|
||||
removeStatus.Err = errors.New(strings.Replace(
|
||||
removeStatus.Err.Error(), "Object is WORM protected",
|
||||
"Object, '"+removeStatus.ObjectName+" (Version ID="+
|
||||
removeStatus.ObjectVersionID+")' is WORM protected", 1))
|
||||
|
||||
// If the removeStatus error message is:
|
||||
// "Object is WORM protected and cannot be overwritten",
|
||||
// it is too generic. We have the object's name and vid.
|
||||
// Adding the object's name and version id into the error msg
|
||||
resultCh <- RemoveResult{
|
||||
Err: probe.NewError(removeStatus.Err),
|
||||
}
|
||||
} else {
|
||||
resultCh <- RemoveResult{
|
||||
RemoveObjectResult: removeStatus,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove last bucket if it qualifies.
|
||||
if isRemoveBucket && prevBucket != "" && !isIncomplete {
|
||||
if err := c.api.RemoveBucket(ctx, prevBucket); err != nil {
|
||||
errorCh <- probe.NewError(err)
|
||||
resultCh <- RemoveResult{
|
||||
Err: probe.NewError(err),
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
return errorCh
|
||||
return resultCh
|
||||
}
|
||||
|
||||
// MakeBucket - make a new bucket.
|
||||
@@ -1560,35 +1606,39 @@ func isVirtualHostStyle(host string, lookup minio.BucketLookupType) bool {
|
||||
return isAmazon(host) && !isAmazonChina(host) || isGoogle(host) || isAmazonAccelerated(host)
|
||||
}
|
||||
|
||||
// url2BucketAndObject gives bucketName and objectName from URL path.
|
||||
func (c *S3Client) url2BucketAndObject() (bucketName, objectName string) {
|
||||
path := c.targetURL.Path
|
||||
func url2BucketAndObject(u *ClientURL, virtualStyle bool) (bucketName, objectName string) {
|
||||
path := u.Path
|
||||
// Convert any virtual host styled requests.
|
||||
//
|
||||
// For the time being this check is introduced for S3,
|
||||
// If you have custom virtual styled hosts please.
|
||||
// List them below.
|
||||
if c.virtualStyle {
|
||||
if virtualStyle {
|
||||
var bucket string
|
||||
hostIndex := strings.Index(c.targetURL.Host, "s3")
|
||||
if hostIndex != -1 && !matchS3InHost(c.targetURL.Host) {
|
||||
hostIndex := strings.Index(u.Host, "s3")
|
||||
if hostIndex != -1 && !matchS3InHost(u.Host) {
|
||||
hostIndex = -1
|
||||
}
|
||||
if hostIndex == -1 {
|
||||
hostIndex = strings.Index(c.targetURL.Host, "s3-accelerate")
|
||||
hostIndex = strings.Index(u.Host, "s3-accelerate")
|
||||
}
|
||||
if hostIndex == -1 {
|
||||
hostIndex = strings.Index(c.targetURL.Host, "storage.googleapis")
|
||||
hostIndex = strings.Index(u.Host, "storage.googleapis")
|
||||
}
|
||||
if hostIndex > 0 {
|
||||
bucket = c.targetURL.Host[:hostIndex-1]
|
||||
path = string(c.targetURL.Separator) + bucket + c.targetURL.Path
|
||||
bucket = u.Host[:hostIndex-1]
|
||||
path = string(u.Separator) + bucket + u.Path
|
||||
}
|
||||
}
|
||||
tokens := splitStr(path, string(c.targetURL.Separator), 3)
|
||||
tokens := splitStr(path, string(u.Separator), 3)
|
||||
return tokens[1], tokens[2]
|
||||
}
|
||||
|
||||
// url2BucketAndObject gives bucketName and objectName from URL path.
|
||||
func (c *S3Client) url2BucketAndObject() (bucketName, objectName string) {
|
||||
return url2BucketAndObject(c.targetURL, c.virtualStyle)
|
||||
}
|
||||
|
||||
// splitPath split path into bucket and object.
|
||||
func (c *S3Client) splitPath(path string) (bucketName, objectName string) {
|
||||
path = strings.TrimPrefix(path, string(c.targetURL.Separator))
|
||||
|
||||
+1
-1
@@ -137,7 +137,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 *probe.Error)
|
||||
Remove(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) (errorCh <-chan RemoveResult)
|
||||
// GetURL returns back internal url
|
||||
GetURL() ClientURL
|
||||
|
||||
|
||||
+9
-7
@@ -317,8 +317,10 @@ func (mj *mirrorJob) doDeleteBucket(ctx context.Context, sURLs URLs) URLs {
|
||||
contentCh <- &ClientContent{URL: clnt.GetURL()}
|
||||
close(contentCh)
|
||||
|
||||
for err := range clnt.Remove(ctx, false, true, false, contentCh) {
|
||||
return sURLs.WithError(err)
|
||||
for result := range clnt.Remove(ctx, false, true, false, contentCh) {
|
||||
if result.Err != nil {
|
||||
return sURLs.WithError(result.Err)
|
||||
}
|
||||
}
|
||||
|
||||
return sURLs.WithError(nil)
|
||||
@@ -341,15 +343,15 @@ func (mj *mirrorJob) doRemove(ctx context.Context, sURLs URLs) URLs {
|
||||
contentCh <- &ClientContent{URL: *newClientURL(sURLs.TargetContent.URL.Path)}
|
||||
close(contentCh)
|
||||
isRemoveBucket := false
|
||||
errorCh := clnt.Remove(ctx, false, isRemoveBucket, false, contentCh)
|
||||
for pErr := range errorCh {
|
||||
if pErr != nil {
|
||||
switch pErr.ToGoError().(type) {
|
||||
resultCh := clnt.Remove(ctx, false, isRemoveBucket, false, contentCh)
|
||||
for result := range resultCh {
|
||||
if result.Err != nil {
|
||||
switch result.Err.ToGoError().(type) {
|
||||
case PathInsufficientPermission:
|
||||
// Ignore Permission error.
|
||||
continue
|
||||
}
|
||||
return sURLs.WithError(pErr)
|
||||
return sURLs.WithError(result.Err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-7
@@ -147,7 +147,7 @@ EXAMPLES:
|
||||
type removeClientInfo struct {
|
||||
client Client
|
||||
contentCh chan *ClientContent
|
||||
errorCh <-chan *probe.Error
|
||||
resultCh <-chan RemoveResult
|
||||
}
|
||||
|
||||
type removeManager struct {
|
||||
@@ -156,12 +156,14 @@ type removeManager struct {
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
func (rm *removeManager) readErrors(errorCh <-chan *probe.Error, targetURL string) {
|
||||
func (rm *removeManager) readErrors(resultCh <-chan RemoveResult, targetURL string) {
|
||||
rm.wg.Add(1)
|
||||
go func() {
|
||||
defer rm.wg.Done()
|
||||
for pErr := range errorCh {
|
||||
errorIf(pErr.Trace(targetURL), "Failed to remove in`"+targetURL+"`.")
|
||||
for result := range resultCh {
|
||||
if result.Err != nil {
|
||||
errorIf(result.Err.Trace(targetURL), "Failed to remove in`"+targetURL+"`.")
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -179,13 +181,13 @@ func (rm *removeManager) add(ctx context.Context, targetAlias, targetURL string)
|
||||
}
|
||||
|
||||
contentCh := make(chan *ClientContent, 10000)
|
||||
errorCh := client.Remove(ctx, false, false, false, contentCh)
|
||||
rm.readErrors(errorCh, targetURL)
|
||||
resultCh := client.Remove(ctx, false, false, false, contentCh)
|
||||
rm.readErrors(resultCh, targetURL)
|
||||
|
||||
clientInfo = &removeClientInfo{
|
||||
client: client,
|
||||
contentCh: contentCh,
|
||||
errorCh: errorCh,
|
||||
resultCh: resultCh,
|
||||
}
|
||||
|
||||
rm.removeMap[targetAlias] = clientInfo
|
||||
|
||||
+5
-3
@@ -159,7 +159,7 @@ func deleteBucket(ctx context.Context, url string, isForce bool) *probe.Error {
|
||||
return pErr
|
||||
}
|
||||
contentCh := make(chan *ClientContent)
|
||||
errorCh := clnt.Remove(ctx, false, false, false, contentCh)
|
||||
resultCh := clnt.Remove(ctx, false, false, false, contentCh)
|
||||
|
||||
go func() {
|
||||
defer close(contentCh)
|
||||
@@ -196,8 +196,10 @@ func deleteBucket(ctx context.Context, url string, isForce bool) *probe.Error {
|
||||
}()
|
||||
|
||||
// Give up on the first error.
|
||||
for perr := range errorCh {
|
||||
return perr
|
||||
for result := range resultCh {
|
||||
if result.Err != nil {
|
||||
return result.Err.Trace(url)
|
||||
}
|
||||
}
|
||||
|
||||
// Remove a bucket without force flag first because force
|
||||
|
||||
+100
-68
@@ -158,16 +158,20 @@ EXAMPLES:
|
||||
|
||||
// Structured message depending on the type of console.
|
||||
type rmMessage struct {
|
||||
Status string `json:"status"`
|
||||
Key string `json:"key"`
|
||||
VersionID string `json:"versionID"`
|
||||
ModTime time.Time `json:"modTime"`
|
||||
Size int64 `json:"size"`
|
||||
Status string `json:"status"`
|
||||
Key string `json:"key"`
|
||||
DeleteMarker bool `json:"deleteMarker"`
|
||||
VersionID string `json:"versionID"`
|
||||
ModTime time.Time `json:"modTime"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
// Colorized message for console printing.
|
||||
func (r rmMessage) String() string {
|
||||
msg := console.Colorize("Remove", fmt.Sprintf("Removing `%s`", r.Key))
|
||||
if r.DeleteMarker {
|
||||
msg = console.Colorize("Remove", fmt.Sprintf("Creating delete marker `%s`", r.Key))
|
||||
}
|
||||
if r.VersionID != "" {
|
||||
if !r.ModTime.IsZero() {
|
||||
msg += fmt.Sprintf(" (versionId=%s, modTime=%s)", r.VersionID, r.ModTime)
|
||||
@@ -291,12 +295,6 @@ func removeSingle(url, versionID string, isIncomplete, isFake, isForce, isBypass
|
||||
return nil
|
||||
}
|
||||
|
||||
printMsg(rmMessage{
|
||||
Key: url,
|
||||
Size: size,
|
||||
VersionID: versionID,
|
||||
})
|
||||
|
||||
if !isFake {
|
||||
targetAlias, targetURL, _ := mustExpandAlias(url)
|
||||
clnt, pErr := newClientFromAlias(targetAlias, targetURL)
|
||||
@@ -313,17 +311,26 @@ func removeSingle(url, versionID string, isIncomplete, isFake, isForce, isBypass
|
||||
contentCh <- &ClientContent{URL: *newClientURL(targetURL), VersionID: versionID}
|
||||
close(contentCh)
|
||||
isRemoveBucket := false
|
||||
errorCh := clnt.Remove(ctx, isIncomplete, isRemoveBucket, isBypass, contentCh)
|
||||
for pErr := range errorCh {
|
||||
if pErr != nil {
|
||||
errorIf(pErr.Trace(url), "Failed to remove `"+url+"`.")
|
||||
switch pErr.ToGoError().(type) {
|
||||
resultCh := clnt.Remove(ctx, isIncomplete, isRemoveBucket, isBypass, contentCh)
|
||||
for result := range resultCh {
|
||||
if result.Err != nil {
|
||||
errorIf(result.Err.Trace(url), "Failed to remove `"+url+"`.")
|
||||
switch result.Err.ToGoError().(type) {
|
||||
case PathInsufficientPermission:
|
||||
// Ignore Permission error.
|
||||
continue
|
||||
}
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
}
|
||||
if result.DeleteMarker {
|
||||
versionID = result.DeleteMarkerVersionID
|
||||
}
|
||||
printMsg(rmMessage{
|
||||
Key: result.ObjectName,
|
||||
Size: size,
|
||||
VersionID: versionID,
|
||||
DeleteMarker: result.DeleteMarker,
|
||||
})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -346,8 +353,6 @@ func listAndRemove(url string, timeRef time.Time, withVersions, nonCurrentVersio
|
||||
contentCh := make(chan *ClientContent)
|
||||
isRemoveBucket := false
|
||||
|
||||
errorCh := clnt.Remove(ctx, isIncomplete, isRemoveBucket, isBypass, contentCh)
|
||||
|
||||
listOpts := ListOptions{Recursive: isRecursive, Incomplete: isIncomplete, ShowDir: DirLast}
|
||||
if !timeRef.IsZero() {
|
||||
listOpts.WithOlderVersions = withVersions
|
||||
@@ -366,6 +371,8 @@ func listAndRemove(url string, timeRef time.Time, withVersions, nonCurrentVersio
|
||||
|
||||
atLeastOneObjectFound := false
|
||||
|
||||
resultCh := clnt.Remove(ctx, isIncomplete, isRemoveBucket, isBypass, contentCh)
|
||||
|
||||
var lastPath string
|
||||
var perObjectVersions []*ClientContent
|
||||
for content := range clnt.List(ctx, listOpts) {
|
||||
@@ -403,23 +410,31 @@ func listAndRemove(url string, timeRef time.Time, withVersions, nonCurrentVersio
|
||||
continue
|
||||
}
|
||||
for _, content := range perObjectVersions {
|
||||
printMsg(rmMessage{
|
||||
Key: targetAlias + content.URL.Path,
|
||||
Size: content.Size,
|
||||
VersionID: content.VersionID,
|
||||
ModTime: content.Time,
|
||||
})
|
||||
select {
|
||||
case contentCh <- content:
|
||||
case pErr := <-errorCh:
|
||||
errorIf(pErr.Trace(content.URL.Path), "Failed to remove `"+content.URL.Path+"`.")
|
||||
switch pErr.ToGoError().(type) {
|
||||
case PathInsufficientPermission:
|
||||
// Ignore Permission error.
|
||||
continue
|
||||
case result := <-resultCh:
|
||||
if result.Err != nil {
|
||||
errorIf(result.Err.Trace(content.URL.Path),
|
||||
"Failed to remove `"+content.URL.Path+"`.")
|
||||
switch result.Err.ToGoError().(type) {
|
||||
case PathInsufficientPermission:
|
||||
// Ignore Permission error.
|
||||
continue
|
||||
}
|
||||
close(contentCh)
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
}
|
||||
close(contentCh)
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
versionID := content.VersionID
|
||||
if content.VersionID == "" {
|
||||
versionID = result.DeleteMarkerVersionID
|
||||
}
|
||||
printMsg(rmMessage{
|
||||
Key: result.ObjectName,
|
||||
Size: content.Size,
|
||||
VersionID: versionID,
|
||||
DeleteMarker: result.DeleteMarker,
|
||||
ModTime: content.Time,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -450,28 +465,35 @@ func listAndRemove(url string, timeRef time.Time, withVersions, nonCurrentVersio
|
||||
continue
|
||||
}
|
||||
|
||||
printMsg(rmMessage{
|
||||
Key: targetAlias + urlString,
|
||||
Size: content.Size,
|
||||
VersionID: content.VersionID,
|
||||
ModTime: content.Time,
|
||||
})
|
||||
|
||||
if !isFake {
|
||||
sent := false
|
||||
for !sent {
|
||||
select {
|
||||
case contentCh <- content:
|
||||
sent = true
|
||||
case pErr := <-errorCh:
|
||||
errorIf(pErr.Trace(urlString), "Failed to remove `"+urlString+"`.")
|
||||
switch pErr.ToGoError().(type) {
|
||||
case PathInsufficientPermission:
|
||||
// Ignore Permission error.
|
||||
continue
|
||||
case result := <-resultCh:
|
||||
if result.Err != nil {
|
||||
errorIf(result.Err.Trace(content.URL.Path),
|
||||
"Failed to remove `"+content.URL.Path+"`.")
|
||||
switch result.Err.ToGoError().(type) {
|
||||
case PathInsufficientPermission:
|
||||
// Ignore Permission error.
|
||||
continue
|
||||
}
|
||||
close(contentCh)
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
}
|
||||
close(contentCh)
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
versionID := content.VersionID
|
||||
if content.VersionID == "" {
|
||||
versionID = result.DeleteMarkerVersionID
|
||||
}
|
||||
printMsg(rmMessage{
|
||||
Key: result.ObjectName,
|
||||
Size: content.Size,
|
||||
VersionID: versionID,
|
||||
DeleteMarker: result.DeleteMarker,
|
||||
ModTime: content.Time,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -483,37 +505,47 @@ func listAndRemove(url string, timeRef time.Time, withVersions, nonCurrentVersio
|
||||
return nil
|
||||
}
|
||||
for _, content := range perObjectVersions {
|
||||
printMsg(rmMessage{
|
||||
Key: targetAlias + content.URL.Path,
|
||||
Size: content.Size,
|
||||
VersionID: content.VersionID,
|
||||
ModTime: content.Time,
|
||||
})
|
||||
select {
|
||||
case contentCh <- content:
|
||||
case pErr := <-errorCh:
|
||||
errorIf(pErr.Trace(content.URL.Path), "Failed to remove `"+content.URL.Path+"`.")
|
||||
switch pErr.ToGoError().(type) {
|
||||
case PathInsufficientPermission:
|
||||
// Ignore Permission error.
|
||||
continue
|
||||
case result := <-resultCh:
|
||||
if result.Err != nil {
|
||||
errorIf(result.Err.Trace(content.URL.Path),
|
||||
"Failed to remove `"+content.URL.Path+"`.")
|
||||
switch result.Err.ToGoError().(type) {
|
||||
case PathInsufficientPermission:
|
||||
// Ignore Permission error.
|
||||
continue
|
||||
}
|
||||
close(contentCh)
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
}
|
||||
close(contentCh)
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
versionID := content.VersionID
|
||||
if content.VersionID == "" {
|
||||
versionID = result.DeleteMarkerVersionID
|
||||
}
|
||||
printMsg(rmMessage{
|
||||
Key: result.ObjectName,
|
||||
Size: content.Size,
|
||||
VersionID: versionID,
|
||||
DeleteMarker: result.DeleteMarker,
|
||||
ModTime: content.Time,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close(contentCh)
|
||||
for pErr := range errorCh {
|
||||
errorIf(pErr.Trace(url), "Failed to remove `"+url+"` recursively.")
|
||||
switch pErr.ToGoError().(type) {
|
||||
case PathInsufficientPermission:
|
||||
// Ignore Permission error.
|
||||
continue
|
||||
for result := range resultCh {
|
||||
if result.Err != nil {
|
||||
errorIf(result.Err.Trace(url), "Failed to remove `"+url+"` recursively.")
|
||||
switch result.Err.ToGoError().(type) {
|
||||
case PathInsufficientPermission:
|
||||
// Ignore Permission error.
|
||||
continue
|
||||
}
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
}
|
||||
return exitStatus(globalErrorExitStatus)
|
||||
}
|
||||
|
||||
if !atLeastOneObjectFound {
|
||||
|
||||
+4
-4
@@ -145,7 +145,7 @@ func undoLastNOperations(ctx context.Context, clnt Client, objectVersions []*Cli
|
||||
}
|
||||
|
||||
contentCh := make(chan *ClientContent)
|
||||
errorCh := clnt.Remove(ctx, false, false, false, contentCh)
|
||||
resultCh := clnt.Remove(ctx, false, false, false, contentCh)
|
||||
|
||||
prefixPath := clnt.GetURL().Path
|
||||
prefixPath = filepath.ToSlash(prefixPath)
|
||||
@@ -177,9 +177,9 @@ func undoLastNOperations(ctx context.Context, clnt Client, objectVersions []*Cli
|
||||
close(contentCh)
|
||||
}()
|
||||
|
||||
for err := range errorCh {
|
||||
if err != nil {
|
||||
errorIf(err.Trace(), "Unable to undo")
|
||||
for result := range resultCh {
|
||||
if result.Err != nil {
|
||||
errorIf(result.Err.Trace(), "Unable to undo")
|
||||
exitErr = exitStatus(globalErrorExitStatus) // Set the exit status.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user