|
@@ -106,17 +106,25 @@ NSMutableDictionary *fileStreams = nil;
|
106
|
106
|
return err == nil;
|
107
|
107
|
}
|
108
|
108
|
|
109
|
|
-+ (NSData *) stat:(NSString *) path error:(NSError **) error{
|
110
|
|
- NSMutableData *stat = [[NSMutableData alloc]init];
|
|
109
|
++ (NSDictionary *) stat:(NSString *) path error:(NSError **) error{
|
|
110
|
+ NSMutableDictionary *stat = [[NSMutableDictionary alloc] init];
|
|
111
|
+ BOOL isDir = NO;
|
111
|
112
|
NSFileManager * fm = [NSFileManager defaultManager];
|
112
|
|
- NSData * info = [fm attributesOfItemAtPath:path error:&error];
|
113
|
|
- [stat setValue:[info valueForKey:NSFileSystemSize] forKey:@"size"];
|
114
|
|
- [stat setValue:path forKey:@"path"];
|
115
|
|
- [stat setValue:[path stringByDeletingPathExtension] forKey:@"filename"];
|
|
113
|
+ if([fm fileExistsAtPath:path isDirectory:&isDir] == NO) {
|
|
114
|
+ return nil;
|
|
115
|
+ }
|
|
116
|
+ NSDictionary * info = [fm attributesOfItemAtPath:path error:&error];
|
|
117
|
+ NSString * size = [NSString stringWithFormat:@"%d", [info fileSize]];
|
|
118
|
+ NSString * filename = [path lastPathComponent];
|
116
|
119
|
NSDate * lastModified;
|
117
|
120
|
[[NSURL fileURLWithPath:path] getResourceValue:&lastModified forKey:NSURLContentModificationDateKey error:&error];
|
118
|
|
- [stat setValue:lastModified forKey:@"lastModified"];
|
119
|
|
- return stat;
|
|
121
|
+ return @{
|
|
122
|
+ @"size" : size,
|
|
123
|
+ @"filename" : filename,
|
|
124
|
+ @"path" : path,
|
|
125
|
+ @"lastModified" : [NSString stringWithFormat:@"%d", [lastModified timeIntervalSince1970]],
|
|
126
|
+ @"type" : isDir ? @"directory" : @"file"
|
|
127
|
+ };
|
120
|
128
|
}
|
121
|
129
|
|
122
|
130
|
+ (BOOL) exists:(NSString *) path {
|
|
@@ -867,7 +875,7 @@ RCT_EXPORT_METHOD(lstat:(NSString *)path callback:(RCTResponseSenderBlock) callb
|
867
|
875
|
NSError * error = nil;
|
868
|
876
|
NSArray * files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];
|
869
|
877
|
|
870
|
|
- NSMutableArray * res = [NSMutableArray alloc];
|
|
878
|
+ NSMutableArray * res = [[NSMutableArray alloc] init];
|
871
|
879
|
if(isDir == YES) {
|
872
|
880
|
for(NSString * p in files) {
|
873
|
881
|
NSString * filePath = [NSString stringWithFormat:@"%@/%@", path, p];
|