Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Unified Diff: sdk/lib/io/file_impl.dart

Issue 52363002: dart:io | Add 'recursive' flag to File.create and Link.create. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove recursive call to create(), simplifying control flow. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
}

Powered by Google App Engine
This is Rietveld 408576698