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

allow cat to take part by part numbers #5026

Merged
merged 1 commit into from
Aug 26, 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
15 changes: 13 additions & 2 deletions cmd/cat-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ var catFlags = []cli.Flag{
Name: "tail",
Usage: "tail number of bytes at ending of file",
},
cli.IntFlag{
Name: "part-number",
Usage: "download only a specific part number",
},
}

// Display contents of a file.
Expand Down Expand Up @@ -162,6 +166,7 @@ type catOpts struct {
timeRef time.Time
startO int64
tailO int64
partN int
isZip bool
stdinMode bool
}
Expand Down Expand Up @@ -197,6 +202,7 @@ func parseCatSyntax(ctx *cli.Context) catOpts {
o.isZip = ctx.Bool("zip")
o.startO = ctx.Int64("offset")
o.tailO = ctx.Int64("tail")
o.partN = ctx.Int("part-number")
if o.tailO != 0 && o.startO != 0 {
fatalIf(errInvalidArgument().Trace(), "You cannot specify both --tail and --offset")
}
Expand All @@ -209,6 +215,9 @@ func parseCatSyntax(ctx *cli.Context) catOpts {
if o.stdinMode && (o.isZip || o.startO != 0 || o.tailO != 0) {
fatalIf(errInvalidArgument().Trace(), "You cannot use --zip --tail or --offset with stdin")
}
if (o.tailO != 0 || o.startO != 0) && o.partN > 0 {
fatalIf(errInvalidArgument().Trace(), "You cannot use --part-number with --tail or --offset")
}

return o
}
Expand Down Expand Up @@ -248,18 +257,20 @@ func catURL(ctx context.Context, sourceURL string, encKeyDB map[string][]prefixS
o.startO = 0
}
}

if client.GetURL().Type == objectStorage {
size = content.Size - o.startO
if size < 0 {
err := probe.NewError(fmt.Errorf("specified offset (%d) bigger than file (%d)", o.startO, content.Size))
return err.Trace(sourceURL)
}
}
if o.partN != 0 {
size = int64(-1)
}
} else {
return err.Trace(sourceURL)
}
gopts := GetOptions{VersionID: versionID, Zip: o.isZip, RangeStart: o.startO}
gopts := GetOptions{VersionID: versionID, Zip: o.isZip, RangeStart: o.startO, PartNumber: o.partN}
if reader, err = getSourceStreamFromURL(ctx, sourceURL, encKeyDB, getSourceOpts{
GetOptions: gopts,
preserve: false,
Expand Down
1 change: 1 addition & 0 deletions cmd/client-s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ func (c *S3Client) Get(ctx context.Context, opts GetOptions) (io.ReadCloser, *Cl
o := minio.GetObjectOptions{
ServerSideEncryption: opts.SSE,
VersionID: opts.VersionID,
PartNumber: opts.PartNumber,
}
if opts.Zip {
o.Set("x-minio-extract", "true")
Expand Down
1 change: 1 addition & 0 deletions cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type GetOptions struct {
VersionID string
Zip bool
RangeStart int64
PartNumber int
Preserve bool
}

Expand Down
Loading