mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Ensure parent directory when creating a new file
createNewFile throws an exception if the parent directory doesn't exist
This commit is contained in:
@@ -327,6 +327,7 @@ export class FileSystemAccess {
|
||||
if (isFolder) {
|
||||
created = javaFile.mkdirs();
|
||||
} else {
|
||||
javaFile.getParentFile().mkdirs();
|
||||
created = javaFile.createNewFile();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,11 +52,12 @@ export class FileSystemAccess {
|
||||
var exists = fileManager.fileExistsAtPath(path);
|
||||
|
||||
if (!exists) {
|
||||
if (!fileManager.createFileAtPathContentsAttributes(path, null, null)) {
|
||||
var parentPath = this.getParent(path, onError).path;
|
||||
if (!fileManager.createDirectoryAtPathWithIntermediateDirectoriesAttributesError(parentPath, true, null) ||
|
||||
!fileManager.createFileAtPathContentsAttributes(path, null, null)) {
|
||||
if (onError) {
|
||||
onError(new Error("Failed to create folder at path '" + path + "'"));
|
||||
onError(new Error("Failed to create file at path '" + path + "'"));
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -406,4 +407,4 @@ export class FileSystemAccess {
|
||||
var nsString = NSString.stringWithString(NSString.pathWithComponents(nsArray));
|
||||
return nsString.stringByStandardizingPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user