From a5ea937df28313b1e2a280d044a6762e67c8e37a Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Thu, 24 Jan 2019 16:13:46 +0100 Subject: [PATCH] mirror: Fix double printing of remove object msg (#2639) Mirror code depends on rm code which naturally prints delete messages, this PR will make mirror uses its own delete code since it is simple enough to do. Also add size information to remove message --- cmd/mirror-main.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index 6a5caf8e..835474d5 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -222,15 +222,30 @@ func (mj *mirrorJob) doRemove(sURLs URLs) URLs { return sURLs.WithError(nil) } - // We are not removing incomplete uploads. - isIncomplete := false - // Construct proper path with alias. targetWithAlias := filepath.Join(sURLs.TargetAlias, sURLs.TargetContent.URL.Path) + clnt, pErr := newClient(targetWithAlias) + if pErr != nil { + return sURLs.WithError(pErr) + } - // Remove extraneous file/bucket on target. - err := probe.NewError(removeSingle(targetWithAlias, isIncomplete, mj.isFake, 0, 0, sURLs.encKeyDB)) - return sURLs.WithError(err) + contentCh := make(chan *clientContent, 1) + contentCh <- &clientContent{URL: *newClientURL(sURLs.TargetContent.URL.Path)} + close(contentCh) + + errorCh := clnt.Remove(false, contentCh) + for pErr := range errorCh { + if pErr != nil { + switch pErr.ToGoError().(type) { + case PathInsufficientPermission: + // Ignore Permission error. + continue + } + return sURLs.WithError(pErr) + } + } + + return sURLs.WithError(nil) } // doMirror - Mirror an object to multiple destination. URLs status contains a copy of sURLs and error if any. @@ -304,7 +319,8 @@ func (mj *mirrorJob) startStatus() { } else if sURLs.TargetContent != nil { // Construct user facing message and path. targetPath := filepath.ToSlash(filepath.Join(sURLs.TargetAlias, sURLs.TargetContent.URL.Path)) - mj.status.PrintMsg(rmMessage{Key: targetPath}) + size := sURLs.TargetContent.Size + mj.status.PrintMsg(rmMessage{Key: targetPath, Size: size}) } } }()