diff --git a/README.md b/README.md
index 31c9da3e..ee240aa4 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,7 @@ and [old][Old Architecture] [RN][React Native] architectures.
[](https://github.com/Crare)
### [Contributors](https://github.com/birdofpreyru/react-native-fs/graphs/contributors)
+[](https://github.com/zenoxs)
[](https://github.com/Crare)
[](https://github.com/stetbern)
[](https://github.com/raphaelheinz)
diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock
index 9f98cb36..3724a7ce 100644
--- a/example/ios/Podfile.lock
+++ b/example/ios/Podfile.lock
@@ -1,7 +1,7 @@
PODS:
- boost (1.83.0)
- DoubleConversion (1.1.6)
- - dr-pogodin-react-native-fs (2.27.0):
+ - dr-pogodin-react-native-fs (2.27.1):
- DoubleConversion
- glog
- hermes-engine
@@ -1391,7 +1391,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
DoubleConversion: 76ab83afb40bddeeee456813d9c04f67f78771b5
- dr-pogodin-react-native-fs: ca26a09ad4b7feb4d7a27b2862273fa2c93396c4
+ dr-pogodin-react-native-fs: 38c2789dd841955bfe1cc7b6ecef80277086c879
dr-pogodin-react-native-static-server: 064d84bba53f863504c6ea874549ea5a70405c42
FBLazyVector: 4bc164e5b5e6cfc288d2b5ff28643ea15fa1a589
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
diff --git a/ios/ReactNativeFs.mm b/ios/ReactNativeFs.mm
index 4e70bbe6..09c477dd 100644
--- a/ios/ReactNativeFs.mm
+++ b/ios/ReactNativeFs.mm
@@ -45,29 +45,64 @@ - (instancetype) init
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
{
- NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
+ NSURL *dirUrl = [ReactNativeFs pathToUrl:dirPath error:&error];
+ if (error) return [[RNFSException fromError:error] reject:reject];
+
+ BOOL allowed = [dirUrl startAccessingSecurityScopedResource];
+
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+
+ @try {
+ NSArray *contents = [fileManager contentsOfDirectoryAtURL:dirUrl
+ includingPropertiesForKeys:@[
+ NSURLContentModificationDateKey, NSURLCreationDateKey,
+ NSURLFileSizeKey, NSURLIsDirectoryKey, NSURLIsRegularFileKey
+ ] options:0 error:&error];
+ NSMutableArray *tagetContents = [[NSMutableArray alloc] init];
+ for (NSURL *url in contents) {
+ NSDictionary *attrs = [url resourceValuesForKeys:@[
+ NSURLContentModificationDateKey, NSURLCreationDateKey,
+ NSURLFileSizeKey, NSURLIsDirectoryKey, NSURLIsRegularFileKey
+ ] error:nil];
+
+ if(attrs != nil) {
+ NSNumber *size = [attrs objectForKey:NSURLFileSizeKey];
+ if (size == nil) size = @(64);
+
+ NSString *path = url.resourceSpecifier;
+
+ NSString *type = @"N/A";
+ if ([[attrs objectForKey:NSURLIsRegularFileKey] boolValue])
+ type = NSFileTypeRegular;
+ else if ([[attrs objectForKey:NSURLIsDirectoryKey] boolValue]) {
+ type = NSFileTypeDirectory;
+
+ // Trims closing dash from the end of folder paths.
+ path = [path substringToIndex:[path length] - 1];
+ }
- NSArray *contents = [fileManager contentsOfDirectoryAtPath:dirPath error:&error];
- NSMutableArray *tagetContents = [[NSMutableArray alloc] init];
- for (NSString *obj in contents) {
- NSString *path = [dirPath stringByAppendingPathComponent:obj];
- NSDictionary *attributes = [fileManager attributesOfItemAtPath:path error:nil];
- if(attributes != nil) {
[tagetContents addObject:@{
- @"ctime": [self dateToTimeIntervalNumber:(NSDate *)[attributes objectForKey:NSFileCreationDate]],
- @"mtime": [self dateToTimeIntervalNumber:(NSDate *)[attributes objectForKey:NSFileModificationDate]],
- @"name": obj,
- @"path": path,
- @"size": [attributes objectForKey:NSFileSize],
- @"type": [attributes objectForKey:NSFileType]
- }];
+ @"ctime": [self dateToTimeIntervalNumber:(NSDate *)[attrs objectForKey:NSURLCreationDateKey]],
+ @"mtime": [self dateToTimeIntervalNumber:(NSDate *)[attrs objectForKey:NSURLContentModificationDateKey]],
+ @"name": url.lastPathComponent,
+ @"path": path,
+ @"size": size,
+ @"type": type
+ }];
+ }
}
- }
- if (error) return [[RNFSException fromError:error] reject:reject];
+ if (error) return [[RNFSException fromError:error] reject:reject];
- resolve(tagetContents);
+ resolve(tagetContents);
+ }
+ @catch (NSException *exception) {
+ reject(@"exception", exception.reason, nil);
+ }
+ @finally {
+ if (allowed) [dirUrl stopAccessingSecurityScopedResource];
+ }
}
RCT_EXPORT_METHOD(exists:(NSString *)filepath
diff --git a/package.json b/package.json
index 301e31f5..ce9b46bd 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@dr.pogodin/react-native-fs",
- "version": "2.27.0",
+ "version": "2.27.1",
"description": "Native filesystem access for React Native",
"main": "lib/commonjs/index",
"module": "lib/module/index",