Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore: Use foundation API instead of C API #12264

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Firestore/core/src/util/filesystem_apple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "Firestore/core/src/util/path.h"
#include "Firestore/core/src/util/statusor.h"
#include "Firestore/core/src/util/string_format.h"
#include "absl/strings/str_cat.h"

namespace firebase {
Expand Down Expand Up @@ -90,6 +91,24 @@
return Path::FromUtf8("/tmp");
}

Status Filesystem::IsDirectory(const Path& path) {
NSFileManager* file_manager = NSFileManager.defaultManager;
NSString* ns_path_str = path.ToNSString();
BOOL is_directory = NO;

if (![file_manager fileExistsAtPath:ns_path_str isDirectory:&is_directory]) {
return Status{Error::kErrorNotFound, path.ToUtf8String()};
}

if (!is_directory) {
return Status{Error::kErrorFailedPrecondition,
StringFormat("Path %s exists but is not a directory",
path.ToUtf8String())};
}

return Status::OK();
}

} // namespace util
} // namespace firestore
} // namespace firebase
Expand Down
2 changes: 2 additions & 0 deletions Firestore/core/src/util/filesystem_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Path Filesystem::TempDir() {
}
#endif // !__APPLE__ && !_WIN32

#if !__APPLE__
Status Filesystem::IsDirectory(const Path& path) {
struct stat buffer {};
if (::stat(path.c_str(), &buffer)) {
Expand Down Expand Up @@ -165,6 +166,7 @@ Status Filesystem::IsDirectory(const Path& path) {

return Status::OK();
}
#endif // !__APPLE__

StatusOr<int64_t> Filesystem::FileSize(const Path& path) {
struct stat st {};
Expand Down
Loading