Chromium Code Reviews| Index: sdk/lib/io/link.dart |
| diff --git a/sdk/lib/io/link.dart b/sdk/lib/io/link.dart |
| index d830e38951f85cb09da1997e8495db606dbe6d12..dfd08f7c463cbda890141a62359d037fab21894c 100644 |
| --- a/sdk/lib/io/link.dart |
| +++ b/sdk/lib/io/link.dart |
| @@ -19,6 +19,11 @@ 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 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 +34,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 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 +54,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 +155,27 @@ 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 new Future.value(null) |
| + .then((_) => recursive ? parent.exists() : true) |
|
Anders Johnsen
2013/10/30 12:23:56
Ditto.
Bill Hesse
2013/10/30 15:07:37
Done.
|
| + .then((exists) => exists ? null : parent.create(recursive: true)) |
| + .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.existsSync()) { |
|
Anders Johnsen
2013/10/30 12:23:56
Ditto.
Bill Hesse
2013/10/30 15:07:37
Done.
|
| + parent.createSync(recursive: true); |
| + } |
| if (Platform.operatingSystem == 'windows') { |
| target = _makeWindowsLinkTarget(target); |
| } |