diff --git a/Firestore/core/src/util/filesystem_apple.mm b/Firestore/core/src/util/filesystem_apple.mm index 85e4db356f0..761e37e0f1d 100644 --- a/Firestore/core/src/util/filesystem_apple.mm +++ b/Firestore/core/src/util/filesystem_apple.mm @@ -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 { @@ -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 diff --git a/Firestore/core/src/util/filesystem_posix.cc b/Firestore/core/src/util/filesystem_posix.cc index cb6ed42b5b7..56c008a8d06 100644 --- a/Firestore/core/src/util/filesystem_posix.cc +++ b/Firestore/core/src/util/filesystem_posix.cc @@ -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)) { @@ -165,6 +166,7 @@ Status Filesystem::IsDirectory(const Path& path) { return Status::OK(); } +#endif // !__APPLE__ StatusOr Filesystem::FileSize(const Path& path) { struct stat st {};