Skip to content

Commit

Permalink
Clean up SbFile usages in base
Browse files Browse the repository at this point in the history
b/302715109
  • Loading branch information
haozheng-cobalt committed May 22, 2024
1 parent 286e132 commit 47da9f6
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 147 deletions.
4 changes: 2 additions & 2 deletions base/files/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class BASE_EXPORT File {
struct BASE_EXPORT Info {
Info();
~Info();
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || defined(STARBOARD)
// Fills this struct with values from |stat_info|.
void FromStat(const stat_wrapper_t& stat_info);
#endif
Expand Down Expand Up @@ -370,7 +370,7 @@ class BASE_EXPORT File {
// Converts an error value to a human-readable form. Used for logging.
static std::string ErrorToString(Error error);

#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) || defined(STARBOARD)
// Wrapper for stat() or stat64().
static int Stat(const char* path, stat_wrapper_t* sb);
static int Fstat(int fd, stat_wrapper_t* sb);
Expand Down
14 changes: 6 additions & 8 deletions base/files/file_enumerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "build/build_config.h"

#if defined(STARBOARD)
#include <sys/stat.h>
#include <unistd.h>
#include "starboard/file.h"
#elif BUILDFLAG(IS_WIN)
#include "base/win/windows_types.h"
Expand Down Expand Up @@ -60,29 +62,25 @@ class BASE_EXPORT FileEnumerator {
// On POSIX systems, this is rounded down to the second.
Time GetLastModifiedTime() const;

#if defined(STARBOARD)
#if defined(STARBOARD) || BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
const stat_wrapper_t& stat() const { return stat_; }
#elif BUILDFLAG(IS_WIN)
// Note that the cAlternateFileName (used to hold the "short" 8.3 name)
// of the WIN32_FIND_DATA will be empty. Since we don't use short file
// names, we tell Windows to omit it which speeds up the query slightly.
const WIN32_FIND_DATA& find_data() const {
return *ChromeToWindowsType(&find_data_);
}
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
const stat_wrapper_t& stat() const { return stat_; }
#endif

private:
friend class FileEnumerator;

#if defined(STARBOARD)
#if defined(STARBOARD) || BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
stat_wrapper_t stat_;
FilePath filename_;
SbFileInfo sb_info_;
#elif BUILDFLAG(IS_WIN)
CHROME_WIN32_FIND_DATA find_data_;
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
stat_wrapper_t stat_;
FilePath filename_;
#endif
};

Expand Down
18 changes: 9 additions & 9 deletions base/files/file_enumerator_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ namespace base {
// FileEnumerator::FileInfo ----------------------------------------------------

FileEnumerator::FileInfo::FileInfo() {
memset(&sb_info_, 0, sizeof(sb_info_));
memset(&stat_, 0, sizeof(stat_));
}

bool FileEnumerator::FileInfo::IsDirectory() const {
return sb_info_.is_directory;
return S_ISDIR(stat_.st_mode);
}

FilePath FileEnumerator::FileInfo::GetName() const {
return filename_;
}

int64_t FileEnumerator::FileInfo::GetSize() const {
return sb_info_.size;
return stat_.st_size;
}

base::Time FileEnumerator::FileInfo::GetLastModifiedTime() const {
return base::Time::FromDeltaSinceWindowsEpoch(
base::TimeDelta::FromMicroseconds(sb_info_.last_modified));
base::TimeDelta::FromMicroseconds(stat_.st_mtime));
}

// FileEnumerator --------------------------------------------------------------
Expand Down Expand Up @@ -124,9 +124,9 @@ std::vector<FileEnumerator::FileInfo> FileEnumerator::ReadDirectory(

FilePath full_name = source.Append(filename);
// TODO: Make sure this follows symlinks on relevant platforms.
if (!SbFileGetPathInfo(full_name.value().c_str(), &info.sb_info_)) {
if (stat(full_name.value().c_str(), &info.stat_) != 0) {
DPLOG(ERROR) << "Couldn't SbFileGetInfo on " << full_name.value();
memset(&info.sb_info_, 0, sizeof(info.sb_info_));
memset(&info.stat_, 0, sizeof(info.stat_));
}
return info;
};
Expand Down Expand Up @@ -186,12 +186,12 @@ FilePath FileEnumerator::Next() {
continue;
}

if (recursive_ && file_info.sb_info_.is_directory) {
if (recursive_ && file_info.IsDirectory()) {
pending_paths_.push(full_path);
}

if ((file_info.sb_info_.is_directory && (file_type_ & DIRECTORIES)) ||
(!file_info.sb_info_.is_directory && (file_type_ & FILES)) ||
if ((file_info.IsDirectory() && (file_type_ & DIRECTORIES)) ||
(!file_info.IsDirectory() && (file_type_ & FILES)) ||
(file_type_ & NAMES_ONLY)) {
directory_entries_.push_back(file_info);
}
Expand Down
Loading

0 comments on commit 47da9f6

Please sign in to comment.