From 3f9fc909dd4a84659b59534d7a3b28be56a9a6f7 Mon Sep 17 00:00:00 2001 From: a-maurice Date: 2025年7月30日 14:54:20 -0700 Subject: [PATCH 1/5] [Storage] Improve how GetFile handles paths --- release_build_files/readme.md | 4 ++++ storage/integration_test/src/integration_test.cc | 3 ++- storage/src/ios/storage_reference_ios.mm | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/release_build_files/readme.md b/release_build_files/readme.md index 2a21483239..c29df4ced4 100644 --- a/release_build_files/readme.md +++ b/release_build_files/readme.md @@ -613,6 +613,10 @@ workflow use only during the development of your app, not for publicly shipping code. ## Release Notes +### Upcoming +- Changes + - Storage (iOS): Handle absolute paths being provided to GetFile. (#1724) + ### 13.0.0 - Changes - General (Android): Update to Firebase Android BoM version 34.0.0. diff --git a/storage/integration_test/src/integration_test.cc b/storage/integration_test/src/integration_test.cc index f430de37de..e8a726f347 100644 --- a/storage/integration_test/src/integration_test.cc +++ b/storage/integration_test/src/integration_test.cc @@ -647,7 +647,8 @@ TEST_F(FirebaseStorageTest, TestPutFileAndGetFile) { std::string path = PathForResource() + kGetFileTestFile; // Cloud Storage expects a URI, so add file:// in front of local // paths. - std::string file_path = kFileUriScheme + path; + // TODO: Revert, just testing to see if this will pass without. + std::string file_path = /*kFileUriScheme +*/ path; LogDebug("Saving to local file: %s", path.c_str()); diff --git a/storage/src/ios/storage_reference_ios.mm b/storage/src/ios/storage_reference_ios.mm index d2260e3416..1db64e4e47 100644 --- a/storage/src/ios/storage_reference_ios.mm +++ b/storage/src/ios/storage_reference_ios.mm @@ -142,7 +142,21 @@ // Cache a copy of the impl and storage, in case this is destroyed before the thread runs. FIRStorageReference* my_impl = impl(); StorageInternal* storage = storage_; - NSURL* local_file_url = [NSURL URLWithString:@(path)]; + NSString* path_string = @(path); + NSURL* local_file_url = nil; + if ([path_string hasPrefix:@"file://"]) { + // If it starts with the prefix, load it assuming a URL string. + local_file_url = [NSURL URLWithString:path_string]; + } else { + // Otherwise, assume it is a file path. + local_file_url = [NSURL fileURLWithPath:path_string]; + } + // If we still failed to convert the path, error out. + if (local_file_url == nil) { + future_impl->Complete(handle, kErrorUnknown, + "Unable to convert provided path to valid URL"); + return GetFileLastResult(); + } util::DispatchAsyncSafeMainQueue(^() { FIRStorageDownloadTask *download_task; { From 5c0be22fd7839fb19533d9dd2a1dab2ee49ab23e Mon Sep 17 00:00:00 2001 From: a-maurice Date: Tue, 5 Aug 2025 11:51:17 -0700 Subject: [PATCH 2/5] Update based on feedback --- .../integration_test/src/integration_test.cc | 25 +++++++++++++++++-- storage/src/ios/storage_reference_ios.mm | 4 +++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/storage/integration_test/src/integration_test.cc b/storage/integration_test/src/integration_test.cc index e8a726f347..6626d68c23 100644 --- a/storage/integration_test/src/integration_test.cc +++ b/storage/integration_test/src/integration_test.cc @@ -647,8 +647,29 @@ TEST_F(FirebaseStorageTest, TestPutFileAndGetFile) { std::string path = PathForResource() + kGetFileTestFile; // Cloud Storage expects a URI, so add file:// in front of local // paths. - // TODO: Revert, just testing to see if this will pass without. - std::string file_path = /*kFileUriScheme +*/ path; + std::string file_path = kFileUriScheme + path; + + LogDebug("Saving to local file: %s", path.c_str()); + + firebase::Future future = + RunWithRetry([&]() { return ref.GetFile(file_path.c_str()); }); + WaitForCompletion(future, "GetFile"); + EXPECT_NE(future.result(), nullptr); + EXPECT_EQ(*future.result(), kSimpleTestFile.size()); + + std::vector buffer(kSimpleTestFile.size()); + FILE* file = fopen(path.c_str(), "rb"); + EXPECT_NE(file, nullptr); + size_t bytes_read = std::fread(&buffer[0], 1, kSimpleTestFile.size(), file); + EXPECT_EQ(bytes_read, kSimpleTestFile.size()); + fclose(file); + EXPECT_EQ(memcmp(&kSimpleTestFile[0], &buffer[0], buffer.size()), 0); + } + // Test GetFile without the file prefix to ensure we can download to a file. + { + std::string path = PathForResource() + kGetFileTestFile; + // Try the direct path, which should also work. + std::string file_path = path; LogDebug("Saving to local file: %s", path.c_str()); diff --git a/storage/src/ios/storage_reference_ios.mm b/storage/src/ios/storage_reference_ios.mm index 1db64e4e47..dbaac100df 100644 --- a/storage/src/ios/storage_reference_ios.mm +++ b/storage/src/ios/storage_reference_ios.mm @@ -143,6 +143,10 @@ FIRStorageReference* my_impl = impl(); StorageInternal* storage = storage_; NSString* path_string = @(path); + if (path_string.length == 0) { + future_impl->Complete(handle, kErrorUnknown, "Path cannot be empty.") + return GetFileLastResult(); + } NSURL* local_file_url = nil; if ([path_string hasPrefix:@"file://"]) { // If it starts with the prefix, load it assuming a URL string. From 5b1d94f86f6d3803e5e1385ff373d3feececbd9c Mon Sep 17 00:00:00 2001 From: a-maurice Date: Tue, 5 Aug 2025 12:44:03 -0700 Subject: [PATCH 3/5] Update storage_reference_ios.mm --- storage/src/ios/storage_reference_ios.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/src/ios/storage_reference_ios.mm b/storage/src/ios/storage_reference_ios.mm index dbaac100df..6f6c139fd2 100644 --- a/storage/src/ios/storage_reference_ios.mm +++ b/storage/src/ios/storage_reference_ios.mm @@ -144,7 +144,7 @@ StorageInternal* storage = storage_; NSString* path_string = @(path); if (path_string.length == 0) { - future_impl->Complete(handle, kErrorUnknown, "Path cannot be empty.") + future_impl->Complete(handle, kErrorUnknown, "Path cannot be empty."); return GetFileLastResult(); } NSURL* local_file_url = nil; From c4294757ba0465b8a34823db451f93c3d7055dfb Mon Sep 17 00:00:00 2001 From: a-maurice Date: Tue, 5 Aug 2025 15:55:10 -0700 Subject: [PATCH 4/5] Update storage_reference_ios.mm --- storage/src/ios/storage_reference_ios.mm | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/storage/src/ios/storage_reference_ios.mm b/storage/src/ios/storage_reference_ios.mm index 6f6c139fd2..fd58d87f2b 100644 --- a/storage/src/ios/storage_reference_ios.mm +++ b/storage/src/ios/storage_reference_ios.mm @@ -147,12 +147,9 @@ future_impl->Complete(handle, kErrorUnknown, "Path cannot be empty."); return GetFileLastResult(); } - NSURL* local_file_url = nil; - if ([path_string hasPrefix:@"file://"]) { - // If it starts with the prefix, load it assuming a URL string. - local_file_url = [NSURL URLWithString:path_string]; - } else { - // Otherwise, assume it is a file path. + NSURL* local_file_url = [NSURL URLWithString:path_string]; + if (local_file_url == nil) { + // If it failed to load as a URL, try loading it is a path. local_file_url = [NSURL fileURLWithPath:path_string]; } // If we still failed to convert the path, error out. From 4d3a96cd94d6ae49ce2eb79e265098779045697e Mon Sep 17 00:00:00 2001 From: a-maurice Date: Tue, 5 Aug 2025 16:51:55 -0700 Subject: [PATCH 5/5] Revert "Update storage_reference_ios.mm" This reverts commit c4294757ba0465b8a34823db451f93c3d7055dfb. --- storage/src/ios/storage_reference_ios.mm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/storage/src/ios/storage_reference_ios.mm b/storage/src/ios/storage_reference_ios.mm index fd58d87f2b..6f6c139fd2 100644 --- a/storage/src/ios/storage_reference_ios.mm +++ b/storage/src/ios/storage_reference_ios.mm @@ -147,9 +147,12 @@ future_impl->Complete(handle, kErrorUnknown, "Path cannot be empty."); return GetFileLastResult(); } - NSURL* local_file_url = [NSURL URLWithString:path_string]; - if (local_file_url == nil) { - // If it failed to load as a URL, try loading it is a path. + NSURL* local_file_url = nil; + if ([path_string hasPrefix:@"file://"]) { + // If it starts with the prefix, load it assuming a URL string. + local_file_url = [NSURL URLWithString:path_string]; + } else { + // Otherwise, assume it is a file path. local_file_url = [NSURL fileURLWithPath:path_string]; } // If we still failed to convert the path, error out.

AltStyle によって変換されたページ (->オリジナル) /