Skip to content
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
4 changes: 2 additions & 2 deletions include/miniocpp/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ struct ObjectReadArgs : public ObjectVersionArgs {
}; // struct ObjectReadArgs

struct ObjectConditionalReadArgs : public ObjectReadArgs {
size_t* offset = nullptr;
size_t* length = nullptr;
std::optional<size_t> offset;
std::optional<size_t> length;
std::string match_etag;
std::string not_match_etag;
utils::UtcTime modified_since;
Expand Down
23 changes: 11 additions & 12 deletions src/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,17 @@ utils::Multimap ObjectWriteArgs::Headers() const {
}

utils::Multimap ObjectConditionalReadArgs::Headers() const {
size_t* off = offset;
size_t* len = length;
std::optional<size_t> off = offset;
std::optional<size_t> len = length;

size_t zero = 0;
if (len != nullptr && off == nullptr) {
off = &zero;
if (len.has_value() && !off.has_value()) {
off = 0;
}

std::string range;
if (off != nullptr) {
if (off.has_value()) {
range = "bytes=" + std::to_string(*off) + "-";
if (len != nullptr) {
if (len.has_value()) {
range += std::to_string(*off + *len - 1);
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Expand Down Expand Up @@ -329,7 +328,7 @@ error::Error CopyObjectArgs::Validate() const {
if (error::Error err = source.Validate()) {
return err;
}
if (source.offset != nullptr || source.length != nullptr) {
if (source.offset.has_value() || source.length.has_value()) {
if (metadata_directive != nullptr &&
*metadata_directive == Directive::kCopy) {
return error::Error(
Expand All @@ -356,22 +355,22 @@ error::Error ComposeSource::BuildHeaders(size_t object_size,
}
msg += ": ";

if (offset != nullptr && *offset >= object_size) {
if (offset.has_value() && *offset >= object_size) {
return error::Error(msg + "offset " + std::to_string(*offset) +
" is beyond object size " +
std::to_string(object_size));
}

if (length != nullptr) {
if (length.has_value()) {
if (*length > object_size) {
return error::Error(msg + "length " + std::to_string(*length) +
" is beyond object size " +
std::to_string(object_size));
}

size_t off = 0;
if (offset != nullptr) off = *offset;
if ((off + *length) > object_size) {
if (offset.has_value()) off = *offset;
if (length.has_value() && (off + *length) > object_size) {
return error::Error(
msg + "compose size " + std::to_string(off + *length) +
" is beyond object size " + std::to_string(object_size));
Expand Down
19 changes: 10 additions & 9 deletions src/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ StatObjectResponse Client::CalculatePartCount(
if (error::Error err = source.BuildHeaders(size, etag)) {
return StatObjectResponse(err);
}
if (source.length != nullptr) {
if (source.length.has_value()) {
size = *source.length;
} else if (source.offset != nullptr) {
} else if (source.offset.has_value()) {
size -= *source.offset;
}

Expand Down Expand Up @@ -349,7 +349,8 @@ ComposeObjectResponse Client::ComposeObject(ComposeObjectArgs args,
}

ComposeSource& source = args.sources.front();
if (part_count == 1 && source.offset == nullptr && source.length == nullptr) {
if (part_count == 1 && !source.offset.has_value() &&
!source.length.has_value()) {
CopyObjectArgs coargs;
coargs.extra_headers = args.extra_headers;
coargs.extra_query_params = args.extra_query_params;
Expand Down Expand Up @@ -389,26 +390,26 @@ ComposeObjectResponse Client::ComposeObject(ComposeObjectArgs args,
std::list<Part> parts;
for (auto& source : args.sources) {
size_t size = source.ObjectSize();
if (source.length != nullptr) {
if (source.length.has_value()) {
size = *source.length;
} else if (source.offset != nullptr) {
} else if (source.offset.has_value()) {
size -= *source.offset;
}

size_t offset = 0;
if (source.offset != nullptr) offset = *source.offset;
if (source.offset.has_value()) offset = *source.offset;

utils::Multimap headers;
headers.AddAll(source.Headers());
headers.AddAll(ssecheaders);

if (size <= utils::kMaxPartSize) {
part_number++;
if (source.length != nullptr) {
if (source.length.has_value()) {
headers.Add("x-amz-copy-source-range",
"bytes=" + std::to_string(offset) + "-" +
std::to_string(offset + *source.length - 1));
} else if (source.offset != nullptr) {
} else if (source.offset.has_value()) {
headers.Add("x-amz-copy-source-range",
"bytes=" + std::to_string(offset) + "-" +
std::to_string(offset + size - 1));
Expand Down Expand Up @@ -785,7 +786,7 @@ CopyObjectResponse Client::CopyObject(CopyObjectArgs args) {
size = resp.size;
}

if (args.source.offset != nullptr || args.source.length != nullptr ||
if (args.source.offset.has_value() || args.source.length.has_value() ||
size > utils::kMaxPartSize) {
if (args.metadata_directive != nullptr &&
*args.metadata_directive == Directive::kCopy) {
Expand Down
Loading