Skip to content

Commit 7c4ebed

Browse files
committed
Update readme and format files
1 parent 48697c7 commit 7c4ebed

7 files changed

Lines changed: 114 additions & 84 deletions

File tree

release_build_files/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ workflow use only during the development of your app, not for publicly shipping
613613
code.
614614

615615
## Release Notes
616+
### Upcoming
617+
- Changes
618+
- Storage: Added `List` API across all platforms.
619+
616620
### 13.5.0
617621
- Changes
618622
- General (Android): Update to Firebase Android BoM version 34.10.0.

storage/integration_test/src/integration_test.cc

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ TEST_F(FirebaseStorageTest, TestList) {
763763
}
764764

765765
// Upload to a subfolder to test prefixes
766-
firebase::storage::StorageReference subfolder_ref = ref.Child("subfolder/sub_file.txt");
766+
firebase::storage::StorageReference subfolder_ref =
767+
ref.Child("subfolder/sub_file.txt");
767768
firebase::Future<firebase::storage::Metadata> subfolder_put_future =
768769
subfolder_ref.PutBytes("sub", 3);
769770
WaitForCompletion(subfolder_put_future, "PutBytes subfolder");
@@ -772,15 +773,18 @@ TEST_F(FirebaseStorageTest, TestList) {
772773

773774
// Test List
774775
LogDebug("Testing List");
775-
firebase::Future<firebase::storage::StorageListResult> list_future = ref.List();
776+
firebase::Future<firebase::storage::StorageListResult> list_future =
777+
ref.List();
776778
WaitForCompletionAnyResult(list_future, "List");
777-
779+
778780
if (list_future.error() != firebase::storage::kErrorNone) {
779-
if (list_future.error() == firebase::storage::kErrorUnknown) {
780-
LogWarning("Skipping TestList as the test project is likely using an older rules_version.");
781-
return;
782-
}
783-
EXPECT_EQ(list_future.error(), firebase::storage::kErrorNone);
781+
if (list_future.error() == firebase::storage::kErrorUnknown) {
782+
LogWarning(
783+
"Skipping TestList as the test project is likely using an older "
784+
"rules_version.");
785+
return;
786+
}
787+
EXPECT_EQ(list_future.error(), firebase::storage::kErrorNone);
784788
}
785789

786790
if (list_future.error() != firebase::storage::kErrorNone) return;
@@ -792,20 +796,24 @@ TEST_F(FirebaseStorageTest, TestList) {
792796

793797
// Test Pagination
794798
LogDebug("Testing List Pagination");
795-
firebase::Future<firebase::storage::StorageListResult> page1_future = ref.List(2);
799+
firebase::Future<firebase::storage::StorageListResult> page1_future =
800+
ref.List(2);
796801
WaitForCompletionAnyResult(page1_future, "List Page 1");
797802
EXPECT_EQ(page1_future.error(), firebase::storage::kErrorNone);
798-
803+
799804
firebase::storage::StorageListResult page1_result = *page1_future.result();
800-
EXPECT_TRUE(page1_result.items().size() + page1_result.prefixes().size() == 2);
805+
EXPECT_TRUE(page1_result.items().size() + page1_result.prefixes().size() ==
806+
2);
801807
EXPECT_NE(page1_result.next_page_token(), "");
802808

803-
firebase::Future<firebase::storage::StorageListResult> page2_future = ref.List(2, page1_result.next_page_token().c_str());
809+
firebase::Future<firebase::storage::StorageListResult> page2_future =
810+
ref.List(2, page1_result.next_page_token().c_str());
804811
WaitForCompletionAnyResult(page2_future, "List Page 2");
805812
EXPECT_EQ(page2_future.error(), firebase::storage::kErrorNone);
806-
813+
807814
firebase::storage::StorageListResult page2_result = *page2_future.result();
808-
EXPECT_TRUE(page2_result.items().size() + page2_result.prefixes().size() == 2);
815+
EXPECT_TRUE(page2_result.items().size() + page2_result.prefixes().size() ==
816+
2);
809817
EXPECT_EQ(page2_result.next_page_token(), "");
810818
}
811819

storage/src/android/storage_reference_android.cc

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,20 +342,26 @@ void StorageReferenceInternal::FutureCallback(JNIEnv* env, jobject result,
342342
std::string page_token = util::JStringToString(env, page_token_jstr);
343343

344344
if (prefixes_list) {
345-
int size = env->CallIntMethod(prefixes_list, util::list::GetMethodId(util::list::kSize));
345+
int size = env->CallIntMethod(prefixes_list,
346+
util::list::GetMethodId(util::list::kSize));
346347
for (int i = 0; i < size; ++i) {
347-
jobject ref_obj = env->CallObjectMethod(prefixes_list, util::list::GetMethodId(util::list::kGet), i);
348-
prefixes.push_back(StorageReference(new StorageReferenceInternal(data->storage, ref_obj)));
348+
jobject ref_obj = env->CallObjectMethod(
349+
prefixes_list, util::list::GetMethodId(util::list::kGet), i);
350+
prefixes.push_back(StorageReference(
351+
new StorageReferenceInternal(data->storage, ref_obj)));
349352
env->DeleteLocalRef(ref_obj);
350353
}
351354
env->DeleteLocalRef(prefixes_list);
352355
}
353356

354357
if (items_list) {
355-
int size = env->CallIntMethod(items_list, util::list::GetMethodId(util::list::kSize));
358+
int size = env->CallIntMethod(items_list,
359+
util::list::GetMethodId(util::list::kSize));
356360
for (int i = 0; i < size; ++i) {
357-
jobject ref_obj = env->CallObjectMethod(items_list, util::list::GetMethodId(util::list::kGet), i);
358-
items.push_back(StorageReference(new StorageReferenceInternal(data->storage, ref_obj)));
361+
jobject ref_obj = env->CallObjectMethod(
362+
items_list, util::list::GetMethodId(util::list::kGet), i);
363+
items.push_back(StorageReference(
364+
new StorageReferenceInternal(data->storage, ref_obj)));
359365
env->DeleteLocalRef(ref_obj);
360366
}
361367
env->DeleteLocalRef(items_list);
@@ -366,9 +372,12 @@ void StorageReferenceInternal::FutureCallback(JNIEnv* env, jobject result,
366372
data->impl->Complete<StorageListResult>(
367373
data->handle, kErrorNone, status_message,
368374
[prefixes, items, page_token](StorageListResult* list_result) {
369-
internal::StorageListResultInternal* list_result_internal = new internal::StorageListResultInternal(
370-
prefixes, items, page_token);
371-
*list_result = internal::StorageListResultInternal::AsStorageListResult(list_result_internal);
375+
internal::StorageListResultInternal* list_result_internal =
376+
new internal::StorageListResultInternal(prefixes, items,
377+
page_token);
378+
*list_result =
379+
internal::StorageListResultInternal::AsStorageListResult(
380+
list_result_internal);
372381
});
373382
} else {
374383
LogDebug("FutureCallback: Completing a Future from a default result.");
@@ -605,7 +614,8 @@ Future<Metadata> StorageReferenceInternal::UpdateMetadataLastResult() {
605614
Future<StorageListResult> StorageReferenceInternal::List(
606615
int max_results_per_page, const char* page_token) {
607616
ReferenceCountedFutureImpl* future_impl = future();
608-
FutureHandle handle = future_impl->Alloc<StorageListResult>(kStorageReferenceFnList);
617+
FutureHandle handle =
618+
future_impl->Alloc<StorageListResult>(kStorageReferenceFnList);
609619

610620
JNIEnv* env = storage_->app()->GetJNIEnv();
611621
jstring page_token_string =

storage/src/common/list_result.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "firebase/storage/list_result.h"
16+
1617
#include "list_result_internal.h"
1718

1819
namespace firebase {
@@ -26,14 +27,17 @@ StorageListResult::~StorageListResult() {
2627
}
2728

2829
StorageListResult::StorageListResult(const StorageListResult& other)
29-
: internal_(other.internal_ ? new internal::StorageListResultInternal(*other.internal_)
30-
: nullptr) {}
30+
: internal_(other.internal_
31+
? new internal::StorageListResultInternal(*other.internal_)
32+
: nullptr) {}
3133

32-
StorageListResult& StorageListResult::operator=(const StorageListResult& other) {
34+
StorageListResult& StorageListResult::operator=(
35+
const StorageListResult& other) {
3336
if (this != &other) {
3437
delete internal_;
35-
internal_ = other.internal_ ? new internal::StorageListResultInternal(*other.internal_)
36-
: nullptr;
38+
internal_ = other.internal_
39+
? new internal::StorageListResultInternal(*other.internal_)
40+
: nullptr;
3741
}
3842
return *this;
3943
}

storage/src/common/list_result_internal.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ class StorageListResultInternal {
3131
StorageListResultInternal(const std::vector<StorageReference>& prefixes,
3232
const std::vector<StorageReference>& items,
3333
const std::string& next_page_token)
34-
: prefixes_(prefixes),
35-
items_(items),
36-
next_page_token_(next_page_token) {}
34+
: prefixes_(prefixes), items_(items), next_page_token_(next_page_token) {}
3735

3836
static StorageListResult AsStorageListResult(
3937
StorageListResultInternal* internal) {

storage/src/desktop/curl_requests.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ void ReturnedListResponse::MarkCompleted() {
317317
if (!prefix_str.empty() && prefix_str.back() == '/') {
318318
prefix_str.pop_back();
319319
}
320-
prefixes.push_back(
321-
storage_->GetReference(prefix_str.c_str())->AsStorageReference());
320+
prefixes.push_back(storage_->GetReference(prefix_str.c_str())
321+
->AsStorageReference());
322322
}
323323
}
324324
}
@@ -330,10 +330,11 @@ void ReturnedListResponse::MarkCompleted() {
330330
auto& item_map = item_variant.map();
331331
if (item_map.find(Variant("name")) != item_map.end() &&
332332
item_map.at(Variant("name")).is_string()) {
333-
items.push_back(storage_
334-
->GetReference(
335-
item_map.at(Variant("name")).string_value())
336-
->AsStorageReference());
333+
items.push_back(
334+
storage_
335+
->GetReference(
336+
item_map.at(Variant("name")).string_value())
337+
->AsStorageReference());
337338
}
338339
}
339340
}
@@ -345,16 +346,19 @@ void ReturnedListResponse::MarkCompleted() {
345346
}
346347

347348
internal::StorageListResultInternal* result_internal =
348-
new internal::StorageListResultInternal(prefixes, items, next_page_token);
349+
new internal::StorageListResultInternal(prefixes, items,
350+
next_page_token);
349351
ref_future_->CompleteWithResult(
350352
handle, kErrorNone, "",
351-
internal::StorageListResultInternal::AsStorageListResult(result_internal));
353+
internal::StorageListResultInternal::AsStorageListResult(
354+
result_internal));
352355
} else {
353356
LogWarning("Failed to parse list response. Buffer: %s", buffer_.c_str());
354357
ref_future_->Complete(handle, kErrorUnknown, kInvalidJsonResponse);
355358
}
356359
} else {
357-
LogWarning("List request failed with status %d. Buffer: %s", status(), buffer_.c_str());
360+
LogWarning("List request failed with status %d. Buffer: %s", status(),
361+
buffer_.c_str());
358362
StorageNetworkError response;
359363
if (response.Parse(buffer_.c_str())) {
360364
ref_future_->Complete(handle, HttpToErrorCode(status()),

storage/src/desktop/storage_reference_desktop.cc

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -644,54 +644,56 @@ Future<StorageListResult> StorageReferenceInternal::List(
644644
future_api->SafeAlloc<StorageListResult>(kStorageReferenceFnList);
645645

646646
std::string page_token_str = page_token ? page_token : "";
647-
auto send_request_funct{[&, max_results_per_page,
648-
page_token_str]() -> BlockingResponse* {
649-
auto* future_api = future();
650-
auto handle = future_api->SafeAlloc<StorageListResult>(
651-
kStorageReferenceFnListInternal);
647+
auto send_request_funct{
648+
[&, max_results_per_page, page_token_str]() -> BlockingResponse* {
649+
auto* future_api = future();
650+
auto handle = future_api->SafeAlloc<StorageListResult>(
651+
kStorageReferenceFnListInternal);
652652

653-
ReturnedListResponse* response =
654-
new ReturnedListResponse(handle, future_api, storage_);
653+
ReturnedListResponse* response =
654+
new ReturnedListResponse(handle, future_api, storage_);
655655

656-
storage::internal::Request* request = new storage::internal::Request();
657-
658-
// For listing, we need the bucket URL: [scheme]://[host]/v0/b/[bucket]/o
659-
// We cannot use storageUri_.AsHttpMetadataUrl() directly because it appends the encoded path
660-
std::string url = storage_->get_scheme();
661-
url += "://";
662-
url += storage_->get_host();
663-
url += ":";
664-
url += std::to_string(storage_->get_port());
665-
url += "/v0/b/";
666-
url += bucket();
667-
url += "/o";
668-
669-
// The prefix must end with a slash to be treated as a directory by the REST
670-
// API.
671-
std::string prefix = storageUri_.GetPath().str();
672-
if (!prefix.empty() && prefix.back() != '/') {
673-
prefix += "/";
674-
}
656+
storage::internal::Request* request = new storage::internal::Request();
675657

676-
// Append query parameters
677-
std::string delimiter = "/";
678-
url += "?delimiter=" + delimiter;
679-
if (!prefix.empty()) {
680-
url += "&prefix=" + rest::util::EncodeUrl(prefix);
681-
}
682-
if (max_results_per_page > 0) {
683-
url += "&maxResults=" + std::to_string(max_results_per_page);
684-
}
685-
if (!page_token_str.empty()) {
686-
url += "&pageToken=" + rest::util::EncodeUrl(page_token_str);
687-
}
658+
// For listing, we need the bucket URL:
659+
// [scheme]://[host]/v0/b/[bucket]/o We cannot use
660+
// storageUri_.AsHttpMetadataUrl() directly because it appends the
661+
// encoded path
662+
std::string url = storage_->get_scheme();
663+
url += "://";
664+
url += storage_->get_host();
665+
url += ":";
666+
url += std::to_string(storage_->get_port());
667+
url += "/v0/b/";
668+
url += bucket();
669+
url += "/o";
670+
671+
// The prefix must end with a slash to be treated as a directory by the
672+
// REST API.
673+
std::string prefix = storageUri_.GetPath().str();
674+
if (!prefix.empty() && prefix.back() != '/') {
675+
prefix += "/";
676+
}
688677

689-
PrepareRequestBlocking(request, url.c_str(), rest::util::kGet);
678+
// Append query parameters
679+
std::string delimiter = "/";
680+
url += "?delimiter=" + delimiter;
681+
if (!prefix.empty()) {
682+
url += "&prefix=" + rest::util::EncodeUrl(prefix);
683+
}
684+
if (max_results_per_page > 0) {
685+
url += "&maxResults=" + std::to_string(max_results_per_page);
686+
}
687+
if (!page_token_str.empty()) {
688+
url += "&pageToken=" + rest::util::EncodeUrl(page_token_str);
689+
}
690690

691-
RestCall(request, request->notifier(), response, handle.get(), nullptr,
692-
nullptr);
693-
return response;
694-
}};
691+
PrepareRequestBlocking(request, url.c_str(), rest::util::kGet);
692+
693+
RestCall(request, request->notifier(), response, handle.get(), nullptr,
694+
nullptr);
695+
return response;
696+
}};
695697

696698
SendRequestWithRetry(kStorageReferenceFnListInternal, send_request_funct,
697699
handle, storage_->max_operation_retry_time());

0 commit comments

Comments
 (0)