Index: sdk/lib/io/file_impl.dart |
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart |
index 71dca70cef7204961ecce61f26c8437a4542c4f9..3ec561bf92636ab84d2a861773b71c7eb4a430f8 100644 |
--- a/sdk/lib/io/file_impl.dart |
+++ b/sdk/lib/io/file_impl.dart |
@@ -244,13 +244,17 @@ class _File extends FileSystemEntity implements File { |
FileStat statSync() => FileStat.statSync(path); |
- Future<File> create() { |
- return _IOService.dispatch(_FILE_CREATE, [path]).then((response) { |
- if (_isErrorResponse(response)) { |
- throw _exceptionFromResponse(response, "Cannot create file", path); |
- } |
- return this; |
- }); |
+ Future<File> create({bool recursive: false}) { |
+ return new Future.value(null) |
+ .then((_) => recursive ? parent.exists() : true) |
Anders Johnsen
2013/10/30 12:23:56
Any reason to call parent.exists()? It should do i
Bill Hesse
2013/10/30 15:07:37
Done.
|
+ .then((exists) => exists ? null : parent.create(recursive: true)) |
+ .then((_) => _IOService.dispatch(_FILE_CREATE, [path])) |
+ .then((response) { |
+ if (_isErrorResponse(response)) { |
+ throw _exceptionFromResponse(response, "Cannot create file", path); |
+ } |
+ return this; |
+ }); |
} |
external static _create(String path); |
@@ -259,7 +263,10 @@ class _File extends FileSystemEntity implements File { |
external static _linkTarget(String path); |
- void createSync() { |
+ void createSync({bool recursive: false}) { |
+ if (recursive && !parent.existsSync()) { |
Anders Johnsen
2013/10/30 12:23:56
Ditto.
Bill Hesse
2013/10/30 15:07:37
Done.
|
+ parent.createSync(recursive: true); |
+ } |
var result = _create(path); |
throwIfError(result, "Cannot create file", path); |
} |