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

Enable stat operations for specific ranges #1846

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
validator
golangci-lint
functional_tests
.idea
.idea
.DS_Store
4 changes: 2 additions & 2 deletions api-get-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ func (c *Client) GetObject(ctx context.Context, bucketName, objectName string, o
} else {
// First request is a Stat or Seek call.
// Only need to run a StatObject until an actual Read or ReadAt request comes through.

// Remove range header if already set, for stat Operations to get original file size.
delete(opts.headers, "Range")
harshavardhana marked this conversation as resolved.
Show resolved Hide resolved
objectInfo, err = c.StatObject(gctx, bucketName, objectName, StatObjectOptions(opts))
Expand Down Expand Up @@ -415,7 +414,8 @@ func (o *Object) Stat() (ObjectInfo, error) {
if o.prevErr != nil && o.prevErr != io.EOF || o.isClosed {
return ObjectInfo{}, o.prevErr
}

o.isStarted = false
o.objectInfoSet = false
klauspost marked this conversation as resolved.
Show resolved Hide resolved
// This is the first request.
if !o.isStarted || !o.objectInfoSet {
// Send the request and get the response.
Expand Down
3 changes: 0 additions & 3 deletions api-put-object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func Test_SSEHeaders(t *testing.T) {
c, err := New("s3.amazonaws.com", &Options{
Transport: rt,
})

if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -147,7 +146,6 @@ func Test_SSEHeaders(t *testing.T) {
uploadID: "upId",
sse: opts.ServerSideEncryption,
})

if err != nil {
t.Error(err)
}
Expand All @@ -167,5 +165,4 @@ func Test_SSEHeaders(t *testing.T) {
}
})
}

}
54 changes: 14 additions & 40 deletions functional_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ func testObjectTaggingWithVersioning() {
successLogger(testName, function, args, startTime).Info()
}

// Test PutObject with custom checksums.
// Test put object with checksums.
func testPutObjectWithChecksums() {
// initialize logging params
startTime := time.Now()
Expand Down Expand Up @@ -2120,14 +2120,15 @@ func testPutObjectWithChecksums() {
})
if err == nil {
if i == 0 && resp.ChecksumCRC32 == "" {
ignoredLog(testName, function, args, startTime, "Checksums does not appear to be supported by backend").Info()
ignoredLog(testName, function, args, startTime, "Checksums do not appear to be supported by backend").Info()
return
}
logError(testName, function, args, startTime, "", "PutObject failed", err)
return
}

// Set correct CRC.
h.Reset()
h.Write(b)
meta[test.header] = base64.StdEncoding.EncodeToString(h.Sum(nil))
reader.Close()
Expand Down Expand Up @@ -2170,43 +2171,12 @@ func testPutObjectWithChecksums() {
return
}

if err := r.Close(); err != nil {
logError(testName, function, args, startTime, "", "Object Close failed", err)
return
}
if err := r.Close(); err == nil {
logError(testName, function, args, startTime, "", "Object already closed, should respond with error", err)
return
}

args["range"] = "true"
err = gopts.SetRange(100, 1000)
if err != nil {
logError(testName, function, args, startTime, "", "SetRange failed", err)
return
}
r, err = c.GetObject(context.Background(), bucketName, objectName, gopts)
if err != nil {
logError(testName, function, args, startTime, "", "GetObject failed", err)
return
}

b, err = io.ReadAll(r)
// Discard the object
minio-trusted marked this conversation as resolved.
Show resolved Hide resolved
_, err = r.Stat()
if err != nil {
logError(testName, function, args, startTime, "", "Read failed", err)
logError(testName, function, args, startTime, "", "Discard object failed", err)
return
}
st, err = r.Stat()
if err != nil {
logError(testName, function, args, startTime, "", "Stat failed", err)
return
}

// Range requests should return empty checksums...
cmpChecksum(st.ChecksumSHA256, "")
cmpChecksum(st.ChecksumSHA1, "")
cmpChecksum(st.ChecksumCRC32, "")
cmpChecksum(st.ChecksumCRC32C, "")

delete(args, "range")
delete(args, "metadata")
Expand Down Expand Up @@ -2471,7 +2441,8 @@ func testTrailingChecksums() {
PO minio.PutObjectOptions
}{
// Currently there is no way to override the checksum type.
{header: "x-amz-checksum-crc32c",
{
header: "x-amz-checksum-crc32c",
hasher: crc32.New(crc32.MakeTable(crc32.Castagnoli)),
ChecksumCRC32C: "set",
PO: minio.PutObjectOptions{
Expand All @@ -2481,7 +2452,8 @@ func testTrailingChecksums() {
PartSize: 5 << 20,
},
},
{header: "x-amz-checksum-crc32c",
{
header: "x-amz-checksum-crc32c",
hasher: crc32.New(crc32.MakeTable(crc32.Castagnoli)),
ChecksumCRC32C: "set",
PO: minio.PutObjectOptions{
Expand All @@ -2491,7 +2463,8 @@ func testTrailingChecksums() {
PartSize: 6_645_654, // Rather arbitrary size
},
},
{header: "x-amz-checksum-crc32c",
{
header: "x-amz-checksum-crc32c",
hasher: crc32.New(crc32.MakeTable(crc32.Castagnoli)),
ChecksumCRC32C: "set",
PO: minio.PutObjectOptions{
Expand All @@ -2501,7 +2474,8 @@ func testTrailingChecksums() {
PartSize: 5 << 20,
},
},
{header: "x-amz-checksum-crc32c",
{
header: "x-amz-checksum-crc32c",
hasher: crc32.New(crc32.MakeTable(crc32.Castagnoli)),
ChecksumCRC32C: "set",
PO: minio.PutObjectOptions{
Expand Down