Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list versions including DEL marker when figuring out Stat() #4951

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/client-s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ func (c *S3Client) Stat(ctx context.Context, opts StatOptions) (*ClientContent,

nonRecursive := false
maxKeys := 1
for objectStat := range c.listObjectWrapper(ctx, bucket, path, nonRecursive, opts.timeRef, false, false, false, maxKeys, opts.isZip) {
for objectStat := range c.listObjectWrapper(ctx, bucket, path, nonRecursive, opts.timeRef, opts.includeVersions, opts.includeVersions, false, maxKeys, opts.isZip) {
if objectStat.Err != nil {
return nil, probe.NewError(objectStat.Err)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type StatOptions struct {
sse encrypt.ServerSide
timeRef time.Time
versionID string
includeVersions bool
isZip bool
ignoreBucketExists bool
}
Expand Down
70 changes: 35 additions & 35 deletions cmd/find-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,21 @@ func checkFindSyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[stri
// ease of repurposing.
type findContext struct {
*cli.Context
execCmd string
ignorePattern string
namePattern string
pathPattern string
regexPattern *regexp.Regexp
maxDepth uint
printFmt string
olderThan string
newerThan string
largerSize uint64
smallerSize uint64
watch bool
withOlderVersions bool
matchMeta map[string]*regexp.Regexp
matchTags map[string]*regexp.Regexp
execCmd string
ignorePattern string
namePattern string
pathPattern string
regexPattern *regexp.Regexp
maxDepth uint
printFmt string
olderThan string
newerThan string
largerSize uint64
smallerSize uint64
watch bool
withVersions bool
matchMeta map[string]*regexp.Regexp
matchTags map[string]*regexp.Regexp

// Internal values
targetAlias string
Expand Down Expand Up @@ -295,25 +295,25 @@ func mainFind(cliCtx *cli.Context) error {
}

return doFind(ctx, &findContext{
Context: cliCtx,
maxDepth: cliCtx.Uint("maxdepth"),
execCmd: cliCtx.String("exec"),
printFmt: cliCtx.String("print"),
namePattern: cliCtx.String("name"),
pathPattern: cliCtx.String("path"),
regexPattern: regMatch,
ignorePattern: cliCtx.String("ignore"),
withOlderVersions: withVersions,
olderThan: olderThan,
newerThan: newerThan,
largerSize: largerSize,
smallerSize: smallerSize,
watch: cliCtx.Bool("watch"),
targetAlias: targetAlias,
targetURL: args[0],
targetFullURL: targetFullURL,
clnt: clnt,
matchMeta: getRegexMap(cliCtx, "metadata"),
matchTags: getRegexMap(cliCtx, "tags"),
Context: cliCtx,
maxDepth: cliCtx.Uint("maxdepth"),
execCmd: cliCtx.String("exec"),
printFmt: cliCtx.String("print"),
namePattern: cliCtx.String("name"),
pathPattern: cliCtx.String("path"),
regexPattern: regMatch,
ignorePattern: cliCtx.String("ignore"),
withVersions: withVersions,
olderThan: olderThan,
newerThan: newerThan,
largerSize: largerSize,
smallerSize: smallerSize,
watch: cliCtx.Bool("watch"),
targetAlias: targetAlias,
targetURL: args[0],
targetFullURL: targetFullURL,
clnt: clnt,
matchMeta: getRegexMap(cliCtx, "metadata"),
matchTags: getRegexMap(cliCtx, "tags"),
})
}
2 changes: 1 addition & 1 deletion cmd/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func doFind(ctxCtx context.Context, ctx *findContext) error {
defer watchFind(ctxCtx, ctx)

lstOptions := ListOptions{
WithOlderVersions: ctx.withOlderVersions,
WithOlderVersions: ctx.withVersions,
WithDeleteMarkers: false,
Recursive: true,
ShowDir: DirFirst,
Expand Down
6 changes: 3 additions & 3 deletions cmd/legalhold-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (l legalHoldInfoMessage) JSON() string {
}

// showLegalHoldInfo - show legalhold for one or many objects within a given prefix, with or without versioning
func showLegalHoldInfo(ctx context.Context, urlStr, versionID string, timeRef time.Time, withOlderVersions, recursive bool) error {
func showLegalHoldInfo(ctx context.Context, urlStr, versionID string, timeRef time.Time, withVersions, recursive bool) error {
clnt, err := newClient(urlStr)
if err != nil {
fatalIf(err.Trace(), "Unable to parse the provided url.")
Expand All @@ -142,7 +142,7 @@ func showLegalHoldInfo(ctx context.Context, urlStr, versionID string, timeRef ti
}
prefixPath = strings.TrimPrefix(prefixPath, "./")

if !recursive && !withOlderVersions {
if !recursive && !withVersions {
lhold, err := clnt.GetObjectLegalHold(ctx, versionID)
if err != nil {
fatalIf(err.Trace(urlStr), "Failed to show legal hold information of `"+urlStr+"`.")
Expand All @@ -167,7 +167,7 @@ func showLegalHoldInfo(ctx context.Context, urlStr, versionID string, timeRef ti
objectsFound := false
lstOptions := ListOptions{Recursive: recursive, ShowDir: DirNone}
if !timeRef.IsZero() {
lstOptions.WithOlderVersions = withOlderVersions
lstOptions.WithOlderVersions = withVersions
lstOptions.TimeRef = timeRef
}
for content := range clnt.List(ctx, lstOptions) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/legalhold-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ EXAMPLES:
}

// setLegalHold - Set legalhold for all objects within a given prefix.
func setLegalHold(ctx context.Context, urlStr, versionID string, timeRef time.Time, withOlderVersions, recursive bool, lhold minio.LegalHoldStatus) error {
func setLegalHold(ctx context.Context, urlStr, versionID string, timeRef time.Time, withVersions, recursive bool, lhold minio.LegalHoldStatus) error {
clnt, err := newClient(urlStr)
if err != nil {
fatalIf(err.Trace(), "Unable to parse the provided url.")
Expand All @@ -95,7 +95,7 @@ func setLegalHold(ctx context.Context, urlStr, versionID string, timeRef time.Ti
}
prefixPath = strings.TrimPrefix(prefixPath, "./")

if !recursive && !withOlderVersions {
if !recursive && !withVersions {
err = clnt.PutObjectLegalHold(ctx, versionID, lhold)
if err != nil {
errorIf(err.Trace(urlStr), "Failed to set legal hold on `"+urlStr+"` successfully")
Expand All @@ -119,7 +119,7 @@ func setLegalHold(ctx context.Context, urlStr, versionID string, timeRef time.Ti
objectsFound := false
lstOptions := ListOptions{Recursive: recursive, ShowDir: DirNone}
if !timeRef.IsZero() {
lstOptions.WithOlderVersions = withOlderVersions
lstOptions.WithOlderVersions = withVersions
lstOptions.TimeRef = timeRef
}
for content := range clnt.List(ctx, lstOptions) {
Expand Down
20 changes: 10 additions & 10 deletions cmd/ls-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,24 @@ func checkListSyntax(cliCtx *cli.Context) ([]string, doListOptions) {

isRecursive := cliCtx.Bool("recursive")
isIncomplete := cliCtx.Bool("incomplete")
withOlderVersions := cliCtx.Bool("versions")
withVersions := cliCtx.Bool("versions")
isSummary := cliCtx.Bool("summarize")
listZip := cliCtx.Bool("zip")

timeRef := parseRewindFlag(cliCtx.String("rewind"))

if listZip && (withOlderVersions || !timeRef.IsZero()) {
if listZip && (withVersions || !timeRef.IsZero()) {
fatalIf(errInvalidArgument().Trace(args...), "Zip file listing can only be performed on the latest version")
}
storageClasss := cliCtx.String("storage-class")
opts := doListOptions{
timeRef: timeRef,
isRecursive: isRecursive,
isIncomplete: isIncomplete,
isSummary: isSummary,
withOlderVersions: withOlderVersions,
listZip: listZip,
filter: storageClasss,
timeRef: timeRef,
isRecursive: isRecursive,
isIncomplete: isIncomplete,
isSummary: isSummary,
withVersions: withVersions,
listZip: listZip,
filter: storageClasss,
}
return args, opts
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func mainList(cliCtx *cli.Context) error {
fatalIf(err.Trace(targetURL), "Unable to initialize target `"+targetURL+"`.")
if !strings.HasSuffix(targetURL, string(clnt.GetURL().Separator)) {
var st *ClientContent
st, err = clnt.Stat(ctx, StatOptions{incomplete: opts.isIncomplete})
st, err = clnt.Stat(ctx, StatOptions{incomplete: opts.isIncomplete, includeVersions: opts.withVersions})
if st != nil && err == nil && st.Type.IsDir() {
targetURL = targetURL + string(clnt.GetURL().Separator)
clnt, err = newClient(targetURL)
Expand Down
20 changes: 10 additions & 10 deletions cmd/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ func printObjectVersions(clntURL ClientURL, ctntVersions []*ClientContent, print
}

type doListOptions struct {
timeRef time.Time
isRecursive bool
isIncomplete bool
isSummary bool
withOlderVersions bool
listZip bool
filter string
timeRef time.Time
isRecursive bool
isIncomplete bool
isSummary bool
withVersions bool
listZip bool
filter string
}

// doList - list all entities inside a folder.
Expand All @@ -230,7 +230,7 @@ func doList(ctx context.Context, clnt Client, o doListOptions) error {
Recursive: o.isRecursive,
Incomplete: o.isIncomplete,
TimeRef: o.timeRef,
WithOlderVersions: o.withOlderVersions || !o.timeRef.IsZero(),
WithOlderVersions: o.withVersions || !o.timeRef.IsZero(),
WithDeleteMarkers: true,
ShowDir: DirNone,
ListZip: o.listZip,
Expand All @@ -247,7 +247,7 @@ func doList(ctx context.Context, clnt Client, o doListOptions) error {

if lastPath != content.URL.Path {
// Print any object in the current list before reinitializing it
printObjectVersions(clnt.GetURL(), perObjectVersions, o.withOlderVersions)
printObjectVersions(clnt.GetURL(), perObjectVersions, o.withVersions)
lastPath = content.URL.Path
perObjectVersions = []*ClientContent{}
}
Expand All @@ -257,7 +257,7 @@ func doList(ctx context.Context, clnt Client, o doListOptions) error {
totalObjects++
}

printObjectVersions(clnt.GetURL(), perObjectVersions, o.withOlderVersions)
printObjectVersions(clnt.GetURL(), perObjectVersions, o.withVersions)

if o.isSummary {
printMsg(summaryMessage{
Expand Down
4 changes: 2 additions & 2 deletions cmd/retention-clear.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func parseClearRetentionArgs(cliCtx *cli.Context) (target, versionID string, tim
}

// Clear Retention for one object/version or many objects within a given prefix, bypass governance is always enabled
func clearRetention(ctx context.Context, target, versionID string, timeRef time.Time, withOlderVersions, isRecursive bool) error {
return applyRetention(ctx, lockOpClear, target, versionID, timeRef, withOlderVersions, isRecursive, "", 0, minio.Days, true)
func clearRetention(ctx context.Context, target, versionID string, timeRef time.Time, withVersions, isRecursive bool) error {
return applyRetention(ctx, lockOpClear, target, versionID, timeRef, withVersions, isRecursive, "", 0, minio.Days, true)
}

func clearBucketLock(urlStr string) error {
Expand Down
6 changes: 3 additions & 3 deletions cmd/retention-common.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func fatalIfBucketLockNotSupported(ctx context.Context, aliasedURL string) {
}

// Apply Retention for one object/version or many objects within a given prefix.
func applyRetention(ctx context.Context, op lockOpType, target, versionID string, timeRef time.Time, withOlderVersions, isRecursive bool,
func applyRetention(ctx context.Context, op lockOpType, target, versionID string, timeRef time.Time, withVersions, isRecursive bool,
mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, bypassGovernance bool,
) error {
clnt, err := newClient(target)
Expand Down Expand Up @@ -207,15 +207,15 @@ func applyRetention(ctx context.Context, op lockOpType, target, versionID string
}

alias, urlStr, _ := mustExpandAlias(target)
if versionID != "" || !isRecursive && !withOlderVersions {
if versionID != "" || !isRecursive && !withVersions {
err := setRetentionSingle(ctx, op, alias, urlStr, versionID, mode, until, bypassGovernance)
fatalIf(err.Trace(), "Unable to set retention on `%s`", target)
return nil
}

lstOptions := ListOptions{Recursive: isRecursive, ShowDir: DirNone}
if !timeRef.IsZero() {
lstOptions.WithOlderVersions = withOlderVersions
lstOptions.WithOlderVersions = withVersions
lstOptions.WithDeleteMarkers = true
lstOptions.TimeRef = timeRef
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/retention-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func infoRetentionSingle(ctx context.Context, alias, url, versionID string, list
}

// Get Retention for one object/version or many objects within a given prefix.
func getRetention(ctx context.Context, target, versionID string, timeRef time.Time, withOlderVersions, isRecursive bool) error {
func getRetention(ctx context.Context, target, versionID string, timeRef time.Time, withVersions, isRecursive bool) error {
clnt, err := newClient(target)
if err != nil {
fatalIf(err.Trace(), "Unable to parse the provided url.")
Expand All @@ -314,7 +314,7 @@ func getRetention(ctx context.Context, target, versionID string, timeRef time.Ti
}

alias, urlStr, _ := mustExpandAlias(target)
if versionID != "" || !isRecursive && !withOlderVersions {
if versionID != "" || !isRecursive && !withVersions {
err := infoRetentionSingle(ctx, alias, urlStr, versionID, false)
if err != nil {
if _, ok := err.ToGoError().(ObjectNameEmpty); ok {
Expand All @@ -327,7 +327,7 @@ func getRetention(ctx context.Context, target, versionID string, timeRef time.Ti

lstOptions := ListOptions{Recursive: isRecursive, ShowDir: DirNone}
if !timeRef.IsZero() {
lstOptions.WithOlderVersions = withOlderVersions
lstOptions.WithOlderVersions = withVersions
lstOptions.WithDeleteMarkers = true
lstOptions.TimeRef = timeRef
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/retention-set.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ func parseSetRetentionArgs(cliCtx *cli.Context) (target, versionID string, recur
}

// Set Retention for one object/version or many objects within a given prefix.
func setRetention(ctx context.Context, target, versionID string, timeRef time.Time, withOlderVersions, isRecursive bool,
func setRetention(ctx context.Context, target, versionID string, timeRef time.Time, withVersions, isRecursive bool,
mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit, bypassGovernance bool,
) error {
return applyRetention(ctx, lockOpSet, target, versionID, timeRef, withOlderVersions, isRecursive, mode, validity, unit, bypassGovernance)
return applyRetention(ctx, lockOpSet, target, versionID, timeRef, withVersions, isRecursive, mode, validity, unit, bypassGovernance)
}

func setBucketLock(urlStr string, mode minio.RetentionMode, validity uint64, unit minio.ValidityUnit) error {
Expand Down
4 changes: 2 additions & 2 deletions cmd/tag-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ func (t tagListMessage) String() string {
}

// parseTagListSyntax performs command-line input validation for tag list command.
func parseTagListSyntax(ctx *cli.Context) (targetURL, versionID string, timeRef time.Time, withOlderVersions, recursive bool) {
func parseTagListSyntax(ctx *cli.Context) (targetURL, versionID string, timeRef time.Time, withVersions, recursive bool) {
if len(ctx.Args()) != 1 {
showCommandHelpAndExit(ctx, globalErrorExitStatus)
}

targetURL = ctx.Args().Get(0)
versionID = ctx.String("version-id")
withOlderVersions = ctx.Bool("versions")
withVersions = ctx.Bool("versions")
rewind := ctx.String("rewind")
recursive = ctx.Bool("recursive")

Expand Down
14 changes: 7 additions & 7 deletions cmd/tree-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ func mainTree(cliCtx *cli.Context) error {
clnt, err := newClientFromAlias(targetAlias, targetURL)
fatalIf(err.Trace(targetURL), "Unable to initialize target `"+targetURL+"`.")
opts := doListOptions{
timeRef: timeRef,
isRecursive: true,
isIncomplete: false,
isSummary: false,
withOlderVersions: false,
listZip: false,
filter: "*",
timeRef: timeRef,
isRecursive: true,
isIncomplete: false,
isSummary: false,
withVersions: false,
listZip: false,
filter: "*",
}
if e := doList(ctx, clnt, opts); e != nil {
cErr = e
Expand Down
Loading