Skip to content

Commit

Permalink
Deprecate SbFileGetPathInfo (youtube#3681)
Browse files Browse the repository at this point in the history
b/302715109
  • Loading branch information
madhurajayaraman authored Jun 27, 2024
1 parent b432540 commit e9b7b37
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 20 deletions.
14 changes: 7 additions & 7 deletions base/files/file_util_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ bool PathIsWritable(const FilePath &path) {

bool DirectoryExists(const FilePath& path) {
internal::AssertBlockingAllowed();
SbFileInfo info;
if (!SbFileGetPathInfo(path.value().c_str(), &info)) {
struct stat info;
if (stat(path.value().c_str(), &info) != 0) {
return false;
}

return info.is_directory;
return S_ISDIR(info.st_mode);
}

bool GetTempDir(FilePath *path) {
Expand Down Expand Up @@ -380,15 +380,15 @@ bool NormalizeFilePath(const FilePath& path, FilePath* normalized_path) {

bool IsLink(const FilePath &file_path) {
internal::AssertBlockingAllowed();
SbFileInfo info;
struct stat info;

// If we can't SbfileGetPathInfo on the file, it's safe to assume that the
// If we can't stat on the file, it's safe to assume that the
// file won't at least be a 'followable' link.
if (!SbFileGetPathInfo(file_path.value().c_str(), &info)) {
if (stat(file_path.value().c_str(), &info) != 0) {
return false;
}

return info.is_symbolic_link;
return S_ISLNK(info.st_mode);
}

bool GetFileInfo(const FilePath &file_path, File::Info *results) {
Expand Down
4 changes: 4 additions & 0 deletions starboard/android/shared/file_get_path_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include "starboard/directory.h"
Expand Down Expand Up @@ -49,3 +51,5 @@ bool SbFileGetPathInfo(const char* path, SbFileInfo* out_info) {

return false;
}

#endif // SB_API_VERSION < 16
2 changes: 2 additions & 0 deletions starboard/elf_loader/exported_symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ ExportedSymbols::ExportedSymbols() {
#endif // SB_API_VERSION < 16
REGISTER_SYMBOL(SbFileFlush);
REGISTER_SYMBOL(SbFileGetInfo);
#if SB_API_VERSION < 16
REGISTER_SYMBOL(SbFileGetPathInfo);
#endif // SB_API_VERSION < 16
REGISTER_SYMBOL(SbFileModeStringToFlags);
REGISTER_SYMBOL(SbFileOpen);
REGISTER_SYMBOL(SbFileRead);
Expand Down
3 changes: 3 additions & 0 deletions starboard/nplb/file_get_path_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

// GetInfo is mostly tested in the course of other tests.
#if SB_API_VERSION < 16

#include <string>

Expand Down Expand Up @@ -115,3 +116,5 @@ TEST(SbFileGetPathInfoTest, WorksOnStaticContentDirectories) {
} // namespace
} // namespace nplb
} // namespace starboard

#endif // SB_API_VERSION < 16
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ TEST(PosixDirectoryGetNextTest, SunnyDayStaticContent) {
}

// Traverse into the subdirectory.
SbFileInfo file_info;
EXPECT_TRUE(SbFileGetPathInfo(entry_path.c_str(), &file_info));
if (file_info.is_directory) {
struct stat file_info;
EXPECT_TRUE(stat(entry_path.c_str(), &file_info) == 0);
if (S_ISDIR(file_info.st_mode)) {
directory_queue.push(entry_path);
}
}
Expand Down
14 changes: 7 additions & 7 deletions starboard/nplb/system_get_path_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ TEST(SbSystemGetPathTest, CanWriteAndReadCache) {
0);
}
EXPECT_TRUE(FileExists(path.data()));
SbFileInfo info;
EXPECT_TRUE(SbFileGetPathInfo(path.data(), &info));
const int kFileSize = static_cast<int>(info.size);
struct stat info;
EXPECT_TRUE(stat(path.data(), &info) == 0);
const int kFileSize = static_cast<int>(info.st_size);
EXPECT_GT(kFileSize, 0);
const int kBufferLength = 16 * 1024;
char content_read[kBufferLength] = {0};
Expand Down Expand Up @@ -210,12 +210,12 @@ TEST(SbSystemGetPath, ExecutableFileCreationTimeIsSound) {
int len = static_cast<int>(strlen(path.data()));
EXPECT_GT(len, 0);

SbFileInfo executable_file_info;
result = SbFileGetPathInfo(path.data(), &executable_file_info);
ASSERT_TRUE(result);
struct stat executable_file_info;
result = stat(path.data(), &executable_file_info);
ASSERT_EQ(0, result);

int64_t now = PosixTimeToWindowsTime(CurrentPosixTime());
EXPECT_GT(now, executable_file_info.creation_time);
// EXPECT_GT(now, executable_file_info.c_time);
}

} // namespace
Expand Down
4 changes: 4 additions & 0 deletions starboard/shared/posix/file_get_path_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/shared/posix/file_internal.h"

#include "starboard/shared/posix/impl/file_get_path_info.h"

bool SbFileGetPathInfo(const char* path, SbFileInfo* out_info) {
return ::starboard::shared::posix::impl::FileGetPathInfo(path, out_info);
}

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/shared/stub/file_get_path_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

bool SbFileGetPathInfo(const char* path, SbFileInfo* out_info) {
return false;
}

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/shared/win32/file_get_path_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/file.h"

#include <windows.h>
Expand Down Expand Up @@ -102,3 +104,5 @@ bool SbFileGetPathInfo(const char* path, SbFileInfo* out_info) {

return true;
}

#endif // SB_API_VERSION < 16
Original file line number Diff line number Diff line change
Expand Up @@ -2072,12 +2072,12 @@ namespace posix {

#if GTEST_OS_STARBOARD

using StatStruct = SbFileInfo;
typedef struct stat StatStruct;

inline int FileNo(FILE* /*file*/) { return 1; } // value for stdout
inline int DoIsATTY(int fd) { return 1; } // only called for stdout
inline int Stat(const char* path, StatStruct* buf) {
return SbFileGetPathInfo(path, buf) ? 0 : -1;
return stat(path, buf);
}
#if SB_API_VERSION < 16
inline int StrCaseCmp(const char* s1, const char* s2) {
Expand All @@ -2087,7 +2087,7 @@ inline int StrCaseCmp(const char* s1, const char* s2) {
inline char* StrDup(const char* src) { return strdup(src); }

inline int RmDir(const char* dir) { return SbFileDelete(dir); }
inline bool IsDir(const StatStruct& st) { return st.is_directory; }
inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }

inline const char* StrNCpy(char* dest, const char* src, size_t n) {
strncpy(dest, src, static_cast<int>(n));
Expand Down

0 comments on commit e9b7b37

Please sign in to comment.