Skip to content

Commit

Permalink
Deprecate SBDirectory extensions
Browse files Browse the repository at this point in the history
b/302730696

Change-Id: I2f74dbec4a99eec4f8f6339d04860ef671544e42
  • Loading branch information
madhurajayaraman committed Nov 28, 2023
1 parent c905013 commit 625ee7c
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 24 deletions.
5 changes: 3 additions & 2 deletions base/files/file_util_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "starboard/directory.h"
#include "starboard/file.h"
#include "starboard/system.h"
#include "sys/stat.h"

namespace base {

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion cobalt/browser/splash_screen_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions cobalt/cache/memory_capped_directory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -54,7 +55,7 @@ bool MemoryCappedDirectory::FileInfo::OldestFirst::operator()(
// static
std::unique_ptr<MemoryCappedDirectory> 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<MemoryCappedDirectory>(
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion starboard/android/shared/android_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
Expand Down
8 changes: 4 additions & 4 deletions starboard/android/shared/system_get_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -110,7 +110,7 @@ bool SbSystemGetPath(SbSystemPathId path_id, char* out_path, int path_size) {
return false;
}

SbDirectoryCreate(path);
mkdir(path, 0700);
break;
}

Expand All @@ -122,7 +122,7 @@ bool SbSystemGetPath(SbSystemPathId path_id, char* out_path, int path_size) {
return false;
}

SbDirectoryCreate(path);
mkdir(path, 0700);
break;
}

Expand All @@ -131,7 +131,7 @@ bool SbSystemGetPath(SbSystemPathId path_id, char* out_path, int path_size) {
return false;
}

SbDirectoryCreate(path);
mkdir(path, 0700);
break;
}

Expand Down
3 changes: 2 additions & 1 deletion starboard/directory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions starboard/elf_loader/exported_symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions starboard/linux/shared/system_get_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions starboard/loader_app/app_key_files_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions starboard/loader_app/drain_file_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions starboard/loader_app/installation_manager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -47,7 +48,7 @@ class InstallationManagerTest : public ::testing::TestWithParam<int> {
}
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;
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion starboard/nplb/directory_can_open_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion starboard/nplb/directory_create_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace starboard {
namespace nplb {
namespace {

#if SB_API_VERSION < 16

const std::string kManyFileSeparators = std::string(kSbFileSepString) +
kSbFileSepString + kSbFileSepString +
kSbFileSepString;
Expand Down Expand Up @@ -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

0 comments on commit 625ee7c

Please sign in to comment.