Skip to content

Commit 6225805

Browse files
authored
Firestore: Use foundation API instead of C API (#12264)
1 parent 4ae0c5d commit 6225805

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Firestore/core/src/util/filesystem_apple.mm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "Firestore/core/src/util/path.h"
2424
#include "Firestore/core/src/util/statusor.h"
25+
#include "Firestore/core/src/util/string_format.h"
2526
#include "absl/strings/str_cat.h"
2627

2728
namespace firebase {
@@ -90,6 +91,24 @@
9091
return Path::FromUtf8("/tmp");
9192
}
9293

94+
Status Filesystem::IsDirectory(const Path& path) {
95+
NSFileManager* file_manager = NSFileManager.defaultManager;
96+
NSString* ns_path_str = path.ToNSString();
97+
BOOL is_directory = NO;
98+
99+
if (![file_manager fileExistsAtPath:ns_path_str isDirectory:&is_directory]) {
100+
return Status{Error::kErrorNotFound, path.ToUtf8String()};
101+
}
102+
103+
if (!is_directory) {
104+
return Status{Error::kErrorFailedPrecondition,
105+
StringFormat("Path %s exists but is not a directory",
106+
path.ToUtf8String())};
107+
}
108+
109+
return Status::OK();
110+
}
111+
93112
} // namespace util
94113
} // namespace firestore
95114
} // namespace firebase

Firestore/core/src/util/filesystem_posix.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Path Filesystem::TempDir() {
130130
}
131131
#endif // !__APPLE__ && !_WIN32
132132

133+
#if !__APPLE__
133134
Status Filesystem::IsDirectory(const Path& path) {
134135
struct stat buffer {};
135136
if (::stat(path.c_str(), &buffer)) {
@@ -165,6 +166,7 @@ Status Filesystem::IsDirectory(const Path& path) {
165166

166167
return Status::OK();
167168
}
169+
#endif // !__APPLE__
168170

169171
StatusOr<int64_t> Filesystem::FileSize(const Path& path) {
170172
struct stat st {};

0 commit comments

Comments
 (0)