@@ -21,14 +21,17 @@ + (NSURL*)baseDirForStorage:(NSString*)storage {
21
21
}
22
22
}
23
23
24
+ + (void )createDirectoriesIfNeeded : (NSURL *)path {
25
+ NSFileManager *fileManager = [NSFileManager defaultManager ];
26
+ NSString *directory = [[path URLByDeletingLastPathComponent ] path ];
27
+ [fileManager createDirectoryAtPath: directory withIntermediateDirectories: YES attributes: nil error: nil ];
28
+
29
+ }
30
+
24
31
+ (void )writeToFile : (NSString *)relativePath content : (NSString *)content inStorage : (NSString *)storage {
25
32
NSURL *baseDir = [RNFileSystem baseDirForStorage: storage];
26
33
NSURL *fullPath = [baseDir URLByAppendingPathComponent: relativePath];
27
-
28
- // create directory structure in case it's not already in place
29
- NSFileManager *fileManager = [NSFileManager defaultManager ];
30
- NSString *directory = [[fullPath URLByDeletingLastPathComponent ] path ];
31
- [fileManager createDirectoryAtPath: directory withIntermediateDirectories: YES attributes: nil error: nil ];
34
+ [RNFileSystem createDirectoriesIfNeeded: fullPath];
32
35
33
36
[content writeToFile: [fullPath path ] atomically: YES encoding: NSUTF8StringEncoding error: nil ];
34
37
if ([storage isEqual: STORAGE_IMPORTANT]) {
@@ -98,6 +101,7 @@ + (void)moveFileFromUrl:(NSURL*)location toRelativePath:(NSString*)relativePath
98
101
NSFileManager *fileManager = [NSFileManager defaultManager ];
99
102
NSURL *baseDir = [RNFileSystem baseDirForStorage: storage];
100
103
NSURL *fullPath = [baseDir URLByAppendingPathComponent: relativePath];
104
+ [RNFileSystem createDirectoriesIfNeeded: fullPath];
101
105
[fileManager moveItemAtURL: location toURL: fullPath error: nil ];
102
106
if ([storage isEqual: STORAGE_IMPORTANT]) {
103
107
[RNFileSystem addSkipBackupAttributeToItemAtPath: [fullPath path ]];
0 commit comments