Skip to content

Commit 3f6b879

Browse files
author
Preben Ludviksen
committed
Fixed so that directories are created automatically for moveFileFromUrl method.
1 parent e661bf4 commit 3f6b879

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ios/RNFileSystem/RNFileSystem.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ + (NSURL*)baseDirForStorage:(NSString*)storage {
2121
}
2222
}
2323

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+
2431
+ (void)writeToFile:(NSString*)relativePath content:(NSString*)content inStorage:(NSString*)storage {
2532
NSURL *baseDir = [RNFileSystem baseDirForStorage:storage];
2633
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];
3235

3336
[content writeToFile:[fullPath path] atomically:YES encoding:NSUTF8StringEncoding error:nil];
3437
if ([storage isEqual:STORAGE_IMPORTANT]) {
@@ -98,6 +101,7 @@ + (void)moveFileFromUrl:(NSURL*)location toRelativePath:(NSString*)relativePath
98101
NSFileManager *fileManager = [NSFileManager defaultManager];
99102
NSURL *baseDir = [RNFileSystem baseDirForStorage:storage];
100103
NSURL *fullPath = [baseDir URLByAppendingPathComponent:relativePath];
104+
[RNFileSystem createDirectoriesIfNeeded:fullPath];
101105
[fileManager moveItemAtURL:location toURL:fullPath error:nil];
102106
if ([storage isEqual:STORAGE_IMPORTANT]) {
103107
[RNFileSystem addSkipBackupAttributeToItemAtPath:[fullPath path]];

0 commit comments

Comments
 (0)