|
7 | 7 |
|
8 | 8 | @implementation RNFileSystem
|
9 | 9 |
|
| 10 | +- (NSDictionary<NSString *, NSString *> *)constantsToExport { |
| 11 | + return @{STORAGE_BACKED_UP: [[RNFileSystem baseDirForStorage:STORAGE_BACKED_UP] path], |
| 12 | + STORAGE_IMPORTANT: [[RNFileSystem baseDirForStorage:STORAGE_IMPORTANT] path], |
| 13 | + STORAGE_AUXILIARY: [[RNFileSystem baseDirForStorage:STORAGE_AUXILIARY] path], |
| 14 | + STORAGE_TEMPORARY: [[RNFileSystem baseDirForStorage:STORAGE_TEMPORARY] path]}; |
| 15 | +} |
| 16 | + |
| 17 | + |
10 | 18 | + (NSURL*)baseDirForStorage:(NSString*)storage {
|
11 | 19 | NSFileManager *fileManager = [NSFileManager defaultManager];
|
12 | 20 | if ([storage isEqual:STORAGE_BACKED_UP]) {
|
13 | 21 | return [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
|
14 |
| - } else if ([storage isEqual:STORAGE_IMPORTANT] || [storage isEqual:STORAGE_AUXILIARY]) { |
15 |
| - return [fileManager URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil]; |
| 22 | + } else if ([storage isEqual:STORAGE_IMPORTANT]) { |
| 23 | + NSURL *cachesDir = [fileManager URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil]; |
| 24 | + return [cachesDir URLByAppendingPathComponent:@"Important"]; |
| 25 | + } else if ([storage isEqual:STORAGE_AUXILIARY]) { |
| 26 | + NSURL *cachesDir = [fileManager URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil]; |
| 27 | + return [cachesDir URLByAppendingPathComponent:@"Auxiliary"]; |
16 | 28 | } else if ([storage isEqual:STORAGE_TEMPORARY]) {
|
17 | 29 | return [NSURL fileURLWithPath:NSTemporaryDirectory()];
|
18 | 30 | } else {
|
@@ -45,7 +57,8 @@ + (NSString*)readFile:(NSString*)relativePath inStorage:(NSString*)storage error
|
45 | 57 | NSFileManager *fileManager = [NSFileManager defaultManager];
|
46 | 58 | BOOL fileExists = [fileManager fileExistsAtPath:[fullPath path]];
|
47 | 59 | if (!fileExists) {
|
48 |
| - NSDictionary *errorDetail = @{NSLocalizedDescriptionKey: @"File does not exist."}; |
| 60 | + NSString* errorMessage = [NSString stringWithFormat:@"File '%@' does not exist in storage: %@", relativePath, storage]; |
| 61 | + NSDictionary *errorDetail = @{NSLocalizedDescriptionKey: errorMessage}; |
49 | 62 | *error = [NSError errorWithDomain:@"FSComponent" code:1 userInfo:errorDetail];
|
50 | 63 | return nil;
|
51 | 64 | }
|
|
0 commit comments