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

Unified Diff: sdk/lib/io/link.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: Indentation. 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
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | tests/standalone/io/create_recursive_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/link.dart
diff --git a/sdk/lib/io/link.dart b/sdk/lib/io/link.dart
index d830e38951f85cb09da1997e8495db606dbe6d12..82aef2a5450b9f971921fd6e8a3e909fbf2c921c 100644
--- a/sdk/lib/io/link.dart
+++ b/sdk/lib/io/link.dart
@@ -19,6 +19,12 @@ abstract class Link implements FileSystemEntity {
* the link when it has been created. If the link exists,
* the future will complete with an error.
*
+ * If [recursive] is false, the default, the link is created
+ * only if all directories in its path exist.
+ * If [recursive] is true, all non-existing path
+ * components are created. The directories in the path of [target] are
+ * not affected, unless they are also in [path].
+ *
* On the Windows platform, this will only work with directories, and the
* target directory must exist. The link will be created as a Junction.
* Only absolute links will be created, and relative paths to the target
@@ -29,12 +35,17 @@ abstract class Link implements FileSystemEntity {
* link containing the string [target]. If [target] is a relative path,
* it will be interpreted relative to the directory containing the link.
*/
- Future<Link> create(String target);
+ Future<Link> create(String target, {bool recursive: false});
/**
* Synchronously create the link. Calling [createSync] on an existing link
* will throw an exception.
*
+ * If [recursive] is false, the default, the link is created only if all
+ * directories in its path exist. If [recursive] is true, all
+ * non-existing path components are created. The directories in
+ * the path of [target] are not affected, unless they are also in [path].
+ *
* On the Windows platform, this will only work with directories, and the
* target directory must exist. The link will be created as a Junction.
* Only absolute links will be created, and relative paths to the target
@@ -44,7 +55,7 @@ abstract class Link implements FileSystemEntity {
* link containing the string [target]. If [target] is a relative path,
* it will be interpreted relative to the directory containing the link.
*/
- void createSync(String target);
+ void createSync(String target, {bool recursive: false});
/**
* Synchronously updates the link. Calling [updateSync] on a non-existing link
@@ -145,21 +156,26 @@ class _Link extends FileSystemEntity implements Link {
FileStat statSync() => FileStat.statSync(path);
- Future<Link> create(String target) {
+ Future<Link> create(String target, {bool recursive: false}) {
if (Platform.operatingSystem == 'windows') {
target = _makeWindowsLinkTarget(target);
}
- return _IOService.dispatch(_FILE_CREATE_LINK, [path, target])
- .then((response) {
- if (_isErrorResponse(response)) {
- throw _exceptionFromResponse(
- response, "Cannot create link to target '$target'", path);
- }
- return this;
- });
+ return (recursive ? parent.create(recursive: true)
+ : new Future.value(null))
+ .then((_) => _IOService.dispatch(_FILE_CREATE_LINK, [path, target]))
+ .then((response) {
+ if (_isErrorResponse(response)) {
+ throw _exceptionFromResponse(
+ response, "Cannot create link to target '$target'", path);
+ }
+ return this;
+ });
}
- void createSync(String target) {
+ void createSync(String target, {bool recursive: false}) {
+ if (recursive) {
+ parent.createSync(recursive: true);
+ }
if (Platform.operatingSystem == 'windows') {
target = _makeWindowsLinkTarget(target);
}
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | tests/standalone/io/create_recursive_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698