Skip to content

Commit

Permalink
Merge branch 'dev-v2.27'
Browse files Browse the repository at this point in the history
  • Loading branch information
birdofpreyru committed Jun 15, 2024
2 parents 5454349 + aedb9f3 commit ef41f0b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and [old][Old Architecture] [RN][React Native] architectures.
[<img width=36 src="https://avatars.githubusercontent.com/u/10487241?s=36" />](https://github.com/Crare)

### [Contributors](https://github.com/birdofpreyru/react-native-fs/graphs/contributors)
[<img width=36 src="https://avatars.githubusercontent.com/u/12350021?s=36" />](https://github.com/zenoxs)
[<img width=36 src="https://avatars.githubusercontent.com/u/10487241?s=36" />](https://github.com/Crare)
[<img width=36 src="https://avatars.githubusercontent.com/u/104437822?s=36" />](https://github.com/stetbern)
[<img width=36 src="https://avatars.githubusercontent.com/u/28300143?s=36" />](https://github.com/raphaelheinz)
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
69 changes: 52 additions & 17 deletions ios/ReactNativeFs.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit ef41f0b

Please sign in to comment.