Skip to content

Commit b8e34d1

Browse files
authored
impl(storage): fix portability and clang-tidy issues (#15149)
1 parent 0511bbc commit b8e34d1

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

google/cloud/storage/examples/storage_object_soft_delete_samples.cc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void ListSoftDeletedObjects(google::cloud::storage::Client client,
2828
std::cout << "Listing soft-deleted objects in the bucket: " << bucket_name
2929
<< "\n";
3030
int object_count = 0;
31-
for (auto const& object_metadata :
31+
for (auto&& object_metadata :
3232
client.ListObjects(bucket_name, gcs::SoftDeleted(true))) {
3333
if (!object_metadata) throw std::move(object_metadata).status();
3434
std::cout << "Soft-deleted object" << ++object_count << ": "
@@ -46,7 +46,7 @@ void ListSoftDeletedObjectVersions(google::cloud::storage::Client client,
4646
[](gcs::Client client, std::string const& bucket_name,
4747
std::string const& object_name) {
4848
int version_count = 0;
49-
for (auto const& object_metadata :
49+
for (auto&& object_metadata :
5050
client.ListObjects(bucket_name, gcs::SoftDeleted(true),
5151
gcs::MatchGlob(object_name))) {
5252
if (!object_metadata) throw std::move(object_metadata).status();
@@ -105,7 +105,7 @@ void RunAll(std::vector<std::string> const& argv) {
105105
if (!insert_obj_metadata.ok()) throw std::move(insert_obj_metadata).status();
106106
std::cout << "Deleting the object: " << object_name << std::endl;
107107
auto obj_delete_status = client.DeleteObject(bucket_name, object_name);
108-
if (!obj_delete_status.ok()) throw obj_delete_status;
108+
if (!obj_delete_status.ok()) throw std::move(obj_delete_status);
109109

110110
std::cout << "\nRunning the ListSoftDeletedObjects() example" << std::endl;
111111
ListSoftDeletedObjects(client, {bucket_name});
@@ -114,24 +114,22 @@ void RunAll(std::vector<std::string> const& argv) {
114114
<< std::endl;
115115
ListSoftDeletedObjectVersions(client, {bucket_name, object_name});
116116

117-
std::int64_t generation = 0;
118-
for (auto const& object_metadata : client.ListObjects(
119-
bucket_name, gcs::SoftDeleted(true), gcs::MatchGlob(object_name))) {
120-
if (!object_metadata) throw std::move(object_metadata).status();
121-
generation = object_metadata->generation();
122-
break;
123-
}
117+
auto objects = client.ListObjects(bucket_name, gcs::SoftDeleted(true),
118+
gcs::MatchGlob(object_name));
119+
auto object_metadata = objects.begin();
120+
if (!*object_metadata) throw std::move(*object_metadata).status();
121+
std::int64_t generation = (*object_metadata)->generation();
124122

125123
std::cout << "\nRunning the RestoreSoftDeletedObject() example" << std::endl;
126124
RestoreSoftDeletedObject(
127125
client, {bucket_name, object_name, std::to_string(generation)});
128126

129127
std::cout << "\nCleanup" << std::endl;
130128
auto object_delete_status = client.DeleteObject(bucket_name, object_name);
131-
if (!object_delete_status.ok()) throw object_delete_status;
129+
if (!object_delete_status.ok()) throw std::move(object_delete_status);
132130
std::cout << "Object deleted successfully.\n";
133131
auto bucket_delete_status = client.DeleteBucket(bucket_name);
134-
if (!bucket_delete_status.ok()) throw bucket_delete_status;
132+
if (!bucket_delete_status.ok()) throw std::move(bucket_delete_status);
135133
std::cout << "Bucket deleted successfully.\n";
136134
}
137135

google/cloud/storage/internal/async/object_descriptor_impl_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,11 +1037,11 @@ Status PartialFailure(std::int64_t read_id) {
10371037
auto error = google::storage::v2::BidiReadObjectError{};
10381038
auto& range_error = *error.add_read_range_errors();
10391039
range_error.set_read_id(read_id);
1040-
range_error.mutable_status()->set_code(grpc::INVALID_ARGUMENT);
1040+
range_error.mutable_status()->set_code(grpc::StatusCode::INVALID_ARGUMENT);
10411041
range_error.mutable_status()->set_message("out of range read");
10421042

10431043
auto details_proto = google::rpc::Status{};
1044-
details_proto.set_code(grpc::INVALID_ARGUMENT);
1044+
details_proto.set_code(grpc::StatusCode::INVALID_ARGUMENT);
10451045
details_proto.set_message("some reads are out of range");
10461046
details_proto.add_details()->PackFrom(error);
10471047

@@ -1051,7 +1051,7 @@ Status PartialFailure(std::int64_t read_id) {
10511051
};
10521052

10531053
return google::cloud::MakeStatusFromRpcError(
1054-
grpc::Status(grpc::INVALID_ARGUMENT, "redirect", details()));
1054+
grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "redirect", details()));
10551055
}
10561056

10571057
/// @test When the underlying stream fails with unrecoverable errors all ranges

0 commit comments

Comments
 (0)