From 625ee7ca02b1db4ec9634bc015eac23695dbce5c Mon Sep 17 00:00:00 2001 From: Madhura Jayaraman Date: Tue, 28 Nov 2023 10:40:54 -0800 Subject: [PATCH] Deprecate SBDirectory extensions b/302730696 Change-Id: I2f74dbec4a99eec4f8f6339d04860ef671544e42 --- base/files/file_util_starboard.cc | 5 +++-- cobalt/browser/splash_screen_cache.cc | 3 ++- cobalt/cache/memory_capped_directory.cc | 5 +++-- starboard/android/shared/android_main.cc | 2 +- starboard/android/shared/system_get_path.cc | 8 ++++---- starboard/directory.h | 3 ++- starboard/elf_loader/exported_symbols.cc | 2 ++ starboard/linux/shared/system_get_path.cc | 10 +++++----- starboard/loader_app/app_key_files_test.cc | 4 ++-- starboard/loader_app/drain_file_test.cc | 4 ++-- starboard/loader_app/installation_manager_test.cc | 5 +++-- starboard/nplb/directory_can_open_test.cc | 3 ++- starboard/nplb/directory_create_test.cc | 4 +++- 13 files changed, 34 insertions(+), 24 deletions(-) diff --git a/base/files/file_util_starboard.cc b/base/files/file_util_starboard.cc index be80ab1605e8..4fba7a75d0ca 100644 --- a/base/files/file_util_starboard.cc +++ b/base/files/file_util_starboard.cc @@ -32,6 +32,7 @@ #include "starboard/directory.h" #include "starboard/file.h" #include "starboard/system.h" +#include "sys/stat.h" namespace base { @@ -317,7 +318,7 @@ bool CreateDirectoryAndGetError(const FilePath &full_path, File::Error* error) { // Fast-path: can the full path be resolved from the full path? if (DirectoryExists(full_path) || - SbDirectoryCreate(full_path.value().c_str())) { + mkdir(full_path.value().c_str(), 0700)) { return true; } @@ -342,7 +343,7 @@ bool CreateDirectoryAndGetError(const FilePath &full_path, File::Error* error) { continue; } - if (!SbDirectoryCreate(i->value().c_str())) { + if (!mkdir(i->value().c_str(), 0700)) { if (error) *error = File::OSErrorToFileError(SbSystemGetLastError()); return false; diff --git a/cobalt/browser/splash_screen_cache.cc b/cobalt/browser/splash_screen_cache.cc index 3e27fdfba7e1..e0268106694e 100644 --- a/cobalt/browser/splash_screen_cache.cc +++ b/cobalt/browser/splash_screen_cache.cc @@ -29,6 +29,7 @@ #include "starboard/common/string.h" #include "starboard/configuration_constants.h" #include "starboard/directory.h" +#include "sys/stat.h" namespace cobalt { namespace browser { @@ -46,7 +47,7 @@ bool CreateDirsForKey(const std::string& key) { starboard::strlcat(path.data(), key.substr(prev_found, found - prev_found).c_str(), kSbFileMaxPath); - if (!SbDirectoryCreate(path.data())) { + if (!mkdir(path.data(), 0700)) { return false; } prev_found = found; diff --git a/cobalt/cache/memory_capped_directory.cc b/cobalt/cache/memory_capped_directory.cc index d6c40fd3fed4..700f79e2e72d 100644 --- a/cobalt/cache/memory_capped_directory.cc +++ b/cobalt/cache/memory_capped_directory.cc @@ -22,6 +22,7 @@ #include "base/json/json_writer.h" #include "base/strings/string_number_conversions.h" #include "starboard/directory.h" +#include "sys/stat.h" namespace cobalt { namespace cache { @@ -54,7 +55,7 @@ bool MemoryCappedDirectory::FileInfo::OldestFirst::operator()( // static std::unique_ptr MemoryCappedDirectory::Create( const base::FilePath& directory_path, uint32_t max_size) { - if (!SbDirectoryCreate(directory_path.value().c_str())) { + if (!mkdir(directory_path.value().c_str(), 0700)) { return nullptr; } auto memory_capped_directory = std::unique_ptr( @@ -118,7 +119,7 @@ void MemoryCappedDirectory::DeleteAll() { // Recursively delete the contents of the directory_path_. base::DeleteFile(directory_path_, true); // Re-create the directory_path_ which will now be empty. - SbDirectoryCreate(directory_path_.value().c_str()); + mkdir(directory_path_.value().c_str(), 0700); file_info_heap_.clear(); file_sizes_.clear(); file_keys_with_metadata_.clear(); diff --git a/starboard/android/shared/android_main.cc b/starboard/android/shared/android_main.cc index 752e659cdf39..3ade7e730bb2 100644 --- a/starboard/android/shared/android_main.cc +++ b/starboard/android/shared/android_main.cc @@ -181,7 +181,7 @@ std::string ExtractCertificatesToFileSystem() { std::string file_system_path(file_system_path_buffer.data()); file_system_path.append(std::string(kSbFileSepString) + "certs"); - if (!SbDirectoryCreate(file_system_path.c_str())) { + if (!mkdir(file_system_path.c_str(), 0700)) { SB_LOG(WARNING) << "Failed to create new dir for CA certificates"; return ""; } diff --git a/starboard/android/shared/system_get_path.cc b/starboard/android/shared/system_get_path.cc index 1bd30ae6a837..22d64edb4411 100644 --- a/starboard/android/shared/system_get_path.cc +++ b/starboard/android/shared/system_get_path.cc @@ -99,7 +99,7 @@ bool SbSystemGetPath(SbSystemPathId path_id, char* out_path, int path_size) { if (starboard::strlcat(path, "/storage", kPathSize) >= kPathSize) { return false; } - SbDirectoryCreate(path); + mkdir(path, 0700); break; } case kSbSystemPathCacheDirectory: { @@ -110,7 +110,7 @@ bool SbSystemGetPath(SbSystemPathId path_id, char* out_path, int path_size) { return false; } - SbDirectoryCreate(path); + mkdir(path, 0700); break; } @@ -122,7 +122,7 @@ bool SbSystemGetPath(SbSystemPathId path_id, char* out_path, int path_size) { return false; } - SbDirectoryCreate(path); + mkdir(path, 0700); break; } @@ -131,7 +131,7 @@ bool SbSystemGetPath(SbSystemPathId path_id, char* out_path, int path_size) { return false; } - SbDirectoryCreate(path); + mkdir(path, 0700); break; } diff --git a/starboard/directory.h b/starboard/directory.h index 087120112eec..4125f459f1e0 100644 --- a/starboard/directory.h +++ b/starboard/directory.h @@ -84,13 +84,14 @@ SB_EXPORT bool SbDirectoryGetNext(SbDirectory directory, // |path|: The path to be checked. SB_EXPORT bool SbDirectoryCanOpen(const char* path); +// #if SB_API_VERSION < 16 // Creates the directory |path|, assuming the parent directory already exists. // This function returns |true| if the directory now exists (even if it existed // before) and returns |false| if the directory does not exist. // // |path|: The path to be created. SB_EXPORT bool SbDirectoryCreate(const char* path); - +// #endif #ifdef __cplusplus } // extern "C" #endif diff --git a/starboard/elf_loader/exported_symbols.cc b/starboard/elf_loader/exported_symbols.cc index c0134d22a875..13d154b923ea 100644 --- a/starboard/elf_loader/exported_symbols.cc +++ b/starboard/elf_loader/exported_symbols.cc @@ -128,7 +128,9 @@ ExportedSymbols::ExportedSymbols() { REGISTER_SYMBOL(SbDecodeTargetRelease); REGISTER_SYMBOL(SbDirectoryCanOpen); REGISTER_SYMBOL(SbDirectoryClose); + // #if SB_API_VERSION < 16 REGISTER_SYMBOL(SbDirectoryCreate); + // #endif //SB_API_VERSION < 16 REGISTER_SYMBOL(SbDirectoryGetNext); REGISTER_SYMBOL(SbDirectoryOpen); REGISTER_SYMBOL(SbDrmCloseSession); diff --git a/starboard/linux/shared/system_get_path.cc b/starboard/linux/shared/system_get_path.cc index eb193f6831c5..2a49e77fdd70 100644 --- a/starboard/linux/shared/system_get_path.cc +++ b/starboard/linux/shared/system_get_path.cc @@ -47,7 +47,7 @@ bool GetCacheDirectory(char* out_path, int path_size) { out_path[0] = '\0'; return false; } - return SbDirectoryCreate(out_path); + return mkdir(out_path, 0700); } // Gets the path to the storage directory, using the home directory. @@ -63,7 +63,7 @@ bool GetStorageDirectory(char* out_path, int path_size) { out_path[0] = '\0'; return false; } - return SbDirectoryCreate(out_path); + return mkdir(out_path, 0700); } // Places up to |path_size| - 1 characters of the path to the current @@ -215,7 +215,7 @@ bool SbSystemGetPath(SbSystemPathId path_id, char* out_path, int path_size) { if (starboard::strlcat(path.data(), "/cobalt", kPathSize) >= kPathSize) { return false; } - if (!SbDirectoryCreate(path.data())) { + if (!mkdir(path.data(), 0700)) { return false; } break; @@ -228,14 +228,14 @@ bool SbSystemGetPath(SbSystemPathId path_id, char* out_path, int path_size) { if (starboard::strlcat(path.data(), "/log", kPathSize) >= kPathSize) { return false; } - SbDirectoryCreate(path.data()); + mkdir(path.data(), 0700); break; case kSbSystemPathTempDirectory: if (!GetTemporaryDirectory(path.data(), kPathSize)) { return false; } - SbDirectoryCreate(path.data()); + mkdir(path.data(), 0700); break; #if SB_API_VERSION < 14 diff --git a/starboard/loader_app/app_key_files_test.cc b/starboard/loader_app/app_key_files_test.cc index 06df41c5cc23..5ce1c0cf03e9 100644 --- a/starboard/loader_app/app_key_files_test.cc +++ b/starboard/loader_app/app_key_files_test.cc @@ -26,7 +26,7 @@ namespace { const char kTestAppKey[] = "test_app_key"; const char kTestAppKeyDir[] = "test_app_key_dir"; - +#if SB_API_VERSION < 16 class AppKeyFilesTest : public testing::Test { protected: virtual void SetUp() { @@ -91,7 +91,7 @@ TEST_F(AppKeyFilesTest, TestAnyGoodKeyFile) { ASSERT_TRUE(AnyGoodAppKeyFile(dir_)); SbFileDelete(file_path.c_str()); } - +#endif // SB_API_VERSION < 16 } // namespace } // namespace loader_app } // namespace starboard diff --git a/starboard/loader_app/drain_file_test.cc b/starboard/loader_app/drain_file_test.cc index a1e0f07ca55b..66efdfd912ca 100644 --- a/starboard/loader_app/drain_file_test.cc +++ b/starboard/loader_app/drain_file_test.cc @@ -34,7 +34,7 @@ namespace { const char kAppKeyOne[] = "b25lDQo="; const char kAppKeyTwo[] = "dHdvDQo="; const char kAppKeyThree[] = "dGhyZWUNCg=="; - +#if SB_API_VERSION < 16 class DrainFileTest : public ::testing::Test { protected: void SetUp() override { @@ -215,7 +215,7 @@ TEST_F(DrainFileTest, RainyDayDrainFileAlreadyExists) { EXPECT_TRUE(DrainFileTryDrain(GetTempDir(), kAppKeyOne)); EXPECT_FALSE(DrainFileTryDrain(GetTempDir(), kAppKeyTwo)); } - +#endif // SB_API_VERSION < 16 } // namespace } // namespace loader_app } // namespace starboard diff --git a/starboard/loader_app/installation_manager_test.cc b/starboard/loader_app/installation_manager_test.cc index d8cdc58642cf..32333fdab3ab 100644 --- a/starboard/loader_app/installation_manager_test.cc +++ b/starboard/loader_app/installation_manager_test.cc @@ -20,6 +20,7 @@ #include "starboard/common/file.h" #include "starboard/configuration_constants.h" #include "starboard/loader_app/installation_store.pb.h" +#include "sys/stat.h" #include "testing/gtest/include/gtest/gtest.h" #if SB_IS(EVERGREEN_COMPATIBLE) @@ -47,7 +48,7 @@ class InstallationManagerTest : public ::testing::TestWithParam { } storage_path_ = buf.data(); ASSERT_TRUE(!storage_path_.empty()); - SbDirectoryCreate(storage_path_.c_str()); + mkdir(storage_path_.c_str(), 0700); installation_store_path_ = storage_path_; installation_store_path_ += kSbFileSepString; @@ -220,7 +221,7 @@ TEST_P(InstallationManagerTest, Reset) { std::string slot_path = buf.data(); slot_path += kSbFileSepString; slot_path += "test_dir"; - SbDirectoryCreate(slot_path.c_str()); + mkdir(slot_path.c_str(), 0700); slot_path += kSbFileSepString; slot_path += "test_file"; created_files.push_back(slot_path); diff --git a/starboard/nplb/directory_can_open_test.cc b/starboard/nplb/directory_can_open_test.cc index f2cb844a9916..dec3f6136b0f 100644 --- a/starboard/nplb/directory_can_open_test.cc +++ b/starboard/nplb/directory_can_open_test.cc @@ -23,6 +23,7 @@ namespace starboard { namespace nplb { namespace { +#if SB_API_VERSION < 16 TEST(SbDirectoryCanOpenTest, SunnyDay) { std::string path = starboard::nplb::GetTempDir(); EXPECT_FALSE(path.empty()); @@ -58,7 +59,7 @@ TEST(SbDirectoryCanOpenTest, FailureRegularFile) { EXPECT_TRUE(SbFileExists(file.filename().c_str())); EXPECT_FALSE(SbDirectoryCanOpen(file.filename().c_str())); } - +#endif // SB_API_VERSION < 16 } // namespace } // namespace nplb } // namespace starboard diff --git a/starboard/nplb/directory_create_test.cc b/starboard/nplb/directory_create_test.cc index ea593ccee6ed..f357e3ee9773 100644 --- a/starboard/nplb/directory_create_test.cc +++ b/starboard/nplb/directory_create_test.cc @@ -25,6 +25,8 @@ namespace starboard { namespace nplb { namespace { +#if SB_API_VERSION < 16 + const std::string kManyFileSeparators = std::string(kSbFileSepString) + kSbFileSepString + kSbFileSepString + kSbFileSepString; @@ -105,7 +107,7 @@ TEST(SbDirectoryCreateTest, FailureNotAbsolute) { EXPECT_FALSE(SbDirectoryCreate(kPath)); EXPECT_FALSE(SbDirectoryCanOpen(kPath)); } - +#endif // SB_API_VERSION < 16 } // namespace } // namespace nplb } // namespace starboard