File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 109
109
return Status::OK ();
110
110
}
111
111
112
+ StatusOr<int64_t > Filesystem::FileSize (const Path& path) {
113
+ NSFileManager * file_manager = NSFileManager .defaultManager ;
114
+ NSString * ns_path_str = path.ToNSString ();
115
+ NSError * error = nil ;
116
+
117
+ NSDictionary * attributes = [file_manager attributesOfItemAtPath: ns_path_str
118
+ error: &error];
119
+
120
+ if (attributes == nil ) {
121
+ if ([error.domain isEqualToString: NSCocoaErrorDomain ]) {
122
+ switch (error.code ) {
123
+ case NSFileReadNoSuchFileError:
124
+ case NSFileNoSuchFileError:
125
+ return Status{Error::kErrorNotFound , path.ToUtf8String ()}.CausedBy (
126
+ Status::FromNSError (error));
127
+ }
128
+ }
129
+
130
+ return Status{Error::kErrorInternal ,
131
+ StringFormat (" attributesOfItemAtPath failed for %s" ,
132
+ path.ToUtf8String ())}
133
+ .CausedBy (Status::FromNSError (error));
134
+ }
135
+
136
+ NSNumber * fileSizeNumber = [attributes objectForKey: NSFileSize ];
137
+
138
+ // Use brace initialization of the in64_t return value so that compilation
139
+ // will fail if the conversion from long long is narrowing.
140
+ return {[fileSizeNumber longLongValue ]};
141
+ }
142
+
112
143
} // namespace util
113
144
} // namespace firestore
114
145
} // namespace firebase
Original file line number Diff line number Diff line change @@ -166,7 +166,6 @@ Status Filesystem::IsDirectory(const Path& path) {
166
166
167
167
return Status::OK ();
168
168
}
169
- #endif // !__APPLE__
170
169
171
170
StatusOr<int64_t > Filesystem::FileSize (const Path& path) {
172
171
struct stat st {};
@@ -177,6 +176,7 @@ StatusOr<int64_t> Filesystem::FileSize(const Path& path) {
177
176
errno, StringFormat (" Failed to stat file: %s" , path.ToUtf8String ()));
178
177
}
179
178
}
179
+ #endif // !__APPLE__
180
180
181
181
Status Filesystem::CreateDir (const Path& path) {
182
182
if (::mkdir (path.c_str (), 0777 )) {
You can’t perform that action at this time.
0 commit comments