diff --git a/cmd/admin-subnet-health.go b/cmd/admin-subnet-health.go index 6d9127dd..36dce978 100644 --- a/cmd/admin-subnet-health.go +++ b/cmd/admin-subnet-health.go @@ -325,7 +325,7 @@ func uploadHealthReport(alias string, filename string, reqURL string, headers ma extractAndSaveAPIKey(alias, resp) // Delete the report after successful upload - deleteFile(filename) + os.Remove(filename) msg := "MinIO health report was successfully uploaded to SUBNET." clusterURL, _ := url.PathUnescape(gjson.Get(resp, "cluster_url").String()) diff --git a/cmd/client-fs.go b/cmd/client-fs.go index f7038dd9..58c46789 100644 --- a/cmd/client-fs.go +++ b/cmd/client-fs.go @@ -449,7 +449,7 @@ func isSysErrNotEmpty(err error) bool { // deleteFile deletes a file path if its empty. If it's successfully deleted, // it will recursively delete empty parent directories // until it finds one with files in it. Returns nil for a non-empty directory. -func deleteFile(deletePath string) error { +func deleteFile(basePath, deletePath string) error { // Attempt to remove path. if e := os.Remove(deletePath); e != nil { if isSysErrNotEmpty(e) { @@ -466,8 +466,15 @@ func deleteFile(deletePath string) error { parentPath := strings.TrimSuffix(deletePath, slashSeperator) parentPath = path.Dir(parentPath) + if !strings.HasPrefix(parentPath, basePath) { + // If parentPath jumps out of the original basePath, + // make sure to cancel such calls, we don't want + // to be deleting more than we should. + return nil + } + if parentPath != "." { - return deleteFile(parentPath) + return deleteFile(basePath, parentPath) } return nil @@ -493,7 +500,7 @@ func (f *fsClient) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB if isIncomplete { name += partSuffix } - e := deleteFile(name) + e := deleteFile(f.PathURL.Path, name) if e == nil { _, objectName := url2BucketAndObject(&content.URL, false) res := RemoveResult{} @@ -501,9 +508,9 @@ func (f *fsClient) Remove(ctx context.Context, isIncomplete, isRemoveBucket, isB resultCh <- res continue } - if os.IsNotExist(e) && isRemoveBucket { - // ignore PathNotFound for dir removal. - return + if os.IsNotExist(e) { + // ignore if path already removed. + continue } if os.IsPermission(e) { // Ignore permission error. @@ -737,6 +744,14 @@ func (f *fsClient) listDirOpt(contentCh chan *ClientContent, isIncomplete bool, listDir = func(currentPath string) (isStop bool) { files, e := readDir(currentPath) if e != nil { + if os.IsNotExist(e) { + contentCh <- &ClientContent{ + Err: probe.NewError(PathNotFound{ + Path: currentPath, + }), + } + return false + } if os.IsPermission(e) { contentCh <- &ClientContent{ Err: probe.NewError(PathInsufficientPermission{ diff --git a/cmd/client-s3.go b/cmd/client-s3.go index b7457749..06415dd7 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -1448,6 +1448,7 @@ func (c *S3Client) statIncompleteUpload(ctx context.Context, bucket, object stri } if objectMultipartInfo.Key == object { + objectMetadata.BucketName = bucket objectMetadata.URL = c.targetURL.Clone() objectMetadata.Time = objectMultipartInfo.Initiated objectMetadata.Size = objectMultipartInfo.Size @@ -1457,6 +1458,7 @@ func (c *S3Client) statIncompleteUpload(ctx context.Context, bucket, object stri } if strings.HasSuffix(objectMultipartInfo.Key, string(c.targetURL.Separator)) { + objectMetadata.BucketName = bucket objectMetadata.URL = c.targetURL.Clone() objectMetadata.Type = os.ModeDir objectMetadata.Metadata = map[string]string{} @@ -1477,9 +1479,11 @@ func (c *S3Client) Stat(ctx context.Context, opts StatOptions) (*ClientContent, if bucket == "" { url := c.targetURL.Clone() url.Path = string(c.targetURL.Separator) - return &ClientContent{URL: url, - Size: 0, - Type: os.ModeDir, + return &ClientContent{ + URL: url, + Size: 0, + Type: os.ModeDir, + BucketName: bucket, }, nil } @@ -1973,6 +1977,7 @@ func (c *S3Client) bucketInfo2ClientContent(bucket minio.BucketInfo) *ClientCont url := c.targetURL.Clone() url.Path = c.joinPath(bucket.Name) content.URL = url + content.BucketName = bucket.Name content.Size = 0 content.Time = bucket.CreationDate content.Type = os.ModeDir @@ -1989,6 +1994,7 @@ func (c *S3Client) objectInfo2ClientContent(bucket string, entry minio.ObjectInf } url.Path = c.joinPath(bucket, entry.Key) content.URL = url + content.BucketName = bucket content.Size = entry.Size content.ETag = entry.ETag content.Time = entry.LastModified @@ -2045,7 +2051,8 @@ func (c *S3Client) bucketStat(ctx context.Context, bucket string) (*ClientConten if !exists { return nil, probe.NewError(BucketDoesNotExist{Bucket: bucket}) } - return &ClientContent{URL: c.targetURL.Clone(), Time: time.Unix(0, 0), Type: os.ModeDir}, nil + return &ClientContent{ + URL: c.targetURL.Clone(), BucketName: bucket, Time: time.Unix(0, 0), Type: os.ModeDir}, nil } func (c *S3Client) listInRoutine(ctx context.Context, contentCh chan *ClientContent, opts ListOptions) { diff --git a/cmd/client.go b/cmd/client.go index 201e1f0c..e45f0ed2 100644 --- a/cmd/client.go +++ b/cmd/client.go @@ -175,6 +175,7 @@ type Client interface { // ClientContent - Content container for content metadata type ClientContent struct { URL ClientURL + BucketName string // only valid and set for client-type objectStorage Time time.Time Size int64 Type os.FileMode diff --git a/cmd/rm-main.go b/cmd/rm-main.go index bd953c1c..0d77527f 100644 --- a/cmd/rm-main.go +++ b/cmd/rm-main.go @@ -23,6 +23,7 @@ import ( "fmt" "net/http" "os" + "path" "path/filepath" "strings" "time" @@ -308,7 +309,8 @@ func removeSingle(url, versionID string, isIncomplete, isFake, isForce, isBypass } contentCh := make(chan *ClientContent, 1) - contentCh <- &ClientContent{URL: *newClientURL(targetURL), VersionID: versionID} + contentURL := *newClientURL(targetURL) + contentCh <- &ClientContent{URL: contentURL, VersionID: versionID} close(contentCh) isRemoveBucket := false resultCh := clnt.Remove(ctx, isIncomplete, isRemoveBucket, isBypass, contentCh) @@ -322,11 +324,11 @@ func removeSingle(url, versionID string, isIncomplete, isFake, isForce, isBypass } return exitStatus(globalErrorExitStatus) } - if result.DeleteMarker { + if versionID == "" { versionID = result.DeleteMarkerVersionID } printMsg(rmMessage{ - Key: result.ObjectName, + Key: targetAlias + contentURL.Path, Size: size, VersionID: versionID, DeleteMarker: result.DeleteMarker, @@ -429,7 +431,7 @@ func listAndRemove(url string, timeRef time.Time, withVersions, nonCurrentVersio versionID = result.DeleteMarkerVersionID } printMsg(rmMessage{ - Key: result.ObjectName, + Key: path.Join(targetAlias, content.BucketName, result.ObjectName), Size: content.Size, VersionID: versionID, DeleteMarker: result.DeleteMarker, @@ -488,7 +490,7 @@ func listAndRemove(url string, timeRef time.Time, withVersions, nonCurrentVersio versionID = result.DeleteMarkerVersionID } printMsg(rmMessage{ - Key: result.ObjectName, + Key: path.Join(targetAlias, content.BucketName, result.ObjectName), Size: content.Size, VersionID: versionID, DeleteMarker: result.DeleteMarker, @@ -524,7 +526,7 @@ func listAndRemove(url string, timeRef time.Time, withVersions, nonCurrentVersio versionID = result.DeleteMarkerVersionID } printMsg(rmMessage{ - Key: result.ObjectName, + Key: path.Join(targetAlias, content.BucketName, result.ObjectName), Size: content.Size, VersionID: versionID, DeleteMarker: result.DeleteMarker,