Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * [Link] objects are references to filesystem links. | 8 * [Link] objects are references to filesystem links. |
| 9 * | 9 * |
| 10 */ | 10 */ |
| 11 abstract class Link implements FileSystemEntity { | 11 abstract class Link implements FileSystemEntity { |
| 12 /** | 12 /** |
| 13 * Creates a Link object. | 13 * Creates a Link object. |
| 14 */ | 14 */ |
| 15 factory Link(String path) => new _Link(path); | 15 factory Link(String path) => new _Link(path); |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Creates a symbolic link. Returns a [:Future<Link>:] that completes with | 18 * Creates a symbolic link. Returns a [:Future<Link>:] that completes with |
| 19 * the link when it has been created. If the link exists, | 19 * the link when it has been created. If the link exists, |
| 20 * the future will complete with an error. | 20 * the future will complete with an error. |
| 21 * | 21 * |
| 22 * If [recursive] is false, the link is created only if all directories | |
| 23 * in its path exist. If [recursive] is true, all non-existing path | |
| 24 * components are created. The directories in the path of [target] are | |
| 25 * not affected, unless they are also in [path]. | |
| 26 * | |
| 22 * On the Windows platform, this will only work with directories, and the | 27 * On the Windows platform, this will only work with directories, and the |
| 23 * target directory must exist. The link will be created as a Junction. | 28 * target directory must exist. The link will be created as a Junction. |
| 24 * Only absolute links will be created, and relative paths to the target | 29 * Only absolute links will be created, and relative paths to the target |
| 25 * will be converted to absolute paths by joining them with the path of the | 30 * will be converted to absolute paths by joining them with the path of the |
| 26 * directory the link is contained in. | 31 * directory the link is contained in. |
| 27 * | 32 * |
| 28 * On other platforms, the posix symlink() call is used to make a symbolic | 33 * On other platforms, the posix symlink() call is used to make a symbolic |
| 29 * link containing the string [target]. If [target] is a relative path, | 34 * link containing the string [target]. If [target] is a relative path, |
| 30 * it will be interpreted relative to the directory containing the link. | 35 * it will be interpreted relative to the directory containing the link. |
| 31 */ | 36 */ |
| 32 Future<Link> create(String target); | 37 Future<Link> create(String target, {bool recursive: false}); |
| 33 | 38 |
| 34 /** | 39 /** |
| 35 * Synchronously create the link. Calling [createSync] on an existing link | 40 * Synchronously create the link. Calling [createSync] on an existing link |
| 36 * will throw an exception. | 41 * will throw an exception. |
| 37 * | 42 * |
| 43 * If [recursive] is false, the link is created only if all directories | |
| 44 * in its path exist. If [recursive] is true, all non-existing path | |
| 45 * components are created. The directories in the path of [target] are | |
| 46 * not affected, unless they are also in [path]. | |
| 47 * | |
| 38 * On the Windows platform, this will only work with directories, and the | 48 * On the Windows platform, this will only work with directories, and the |
| 39 * target directory must exist. The link will be created as a Junction. | 49 * target directory must exist. The link will be created as a Junction. |
| 40 * Only absolute links will be created, and relative paths to the target | 50 * Only absolute links will be created, and relative paths to the target |
| 41 * will be converted to absolute paths. | 51 * will be converted to absolute paths. |
| 42 * | 52 * |
| 43 * On other platforms, the posix symlink() call is used to make a symbolic | 53 * On other platforms, the posix symlink() call is used to make a symbolic |
| 44 * link containing the string [target]. If [target] is a relative path, | 54 * link containing the string [target]. If [target] is a relative path, |
| 45 * it will be interpreted relative to the directory containing the link. | 55 * it will be interpreted relative to the directory containing the link. |
| 46 */ | 56 */ |
| 47 void createSync(String target); | 57 void createSync(String target, {bool recursive: false}); |
| 48 | 58 |
| 49 /** | 59 /** |
| 50 * Synchronously updates the link. Calling [updateSync] on a non-existing link | 60 * Synchronously updates the link. Calling [updateSync] on a non-existing link |
| 51 * will throw an exception. | 61 * will throw an exception. |
| 52 * | 62 * |
| 53 * On the Windows platform, this will only work with directories, and the | 63 * On the Windows platform, this will only work with directories, and the |
| 54 * target directory must exist. | 64 * target directory must exist. |
| 55 */ | 65 */ |
| 56 void updateSync(String target); | 66 void updateSync(String target); |
| 57 | 67 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 Future<bool> exists() => FileSystemEntity.isLink(path); | 148 Future<bool> exists() => FileSystemEntity.isLink(path); |
| 139 | 149 |
| 140 bool existsSync() => FileSystemEntity.isLinkSync(path); | 150 bool existsSync() => FileSystemEntity.isLinkSync(path); |
| 141 | 151 |
| 142 Link get absolute => new Link(_absolutePath); | 152 Link get absolute => new Link(_absolutePath); |
| 143 | 153 |
| 144 Future<FileStat> stat() => FileStat.stat(path); | 154 Future<FileStat> stat() => FileStat.stat(path); |
| 145 | 155 |
| 146 FileStat statSync() => FileStat.statSync(path); | 156 FileStat statSync() => FileStat.statSync(path); |
| 147 | 157 |
| 148 Future<Link> create(String target) { | 158 Future<Link> create(String target, {bool recursive: false}) { |
| 149 if (Platform.operatingSystem == 'windows') { | 159 if (Platform.operatingSystem == 'windows') { |
| 150 target = _makeWindowsLinkTarget(target); | 160 target = _makeWindowsLinkTarget(target); |
| 151 } | 161 } |
| 152 return _IOService.dispatch(_FILE_CREATE_LINK, [path, target]) | 162 return new Future.value(null) |
| 153 .then((response) { | 163 .then((_) => recursive ? parent.exists() : true) |
|
Anders Johnsen
2013/10/30 12:23:56
Ditto.
Bill Hesse
2013/10/30 15:07:37
Done.
| |
| 154 if (_isErrorResponse(response)) { | 164 .then((exists) => exists ? null : parent.create(recursive: true)) |
| 155 throw _exceptionFromResponse( | 165 .then((_) => _IOService.dispatch(_FILE_CREATE_LINK, [path, target])) |
| 156 response, "Cannot create link to target '$target'", path); | 166 .then((response) { |
| 157 } | 167 if (_isErrorResponse(response)) { |
| 158 return this; | 168 throw _exceptionFromResponse( |
| 159 }); | 169 response, "Cannot create link to target '$target'", path); |
| 170 } | |
| 171 return this; | |
| 172 }); | |
| 160 } | 173 } |
| 161 | 174 |
| 162 void createSync(String target) { | 175 void createSync(String target, {bool recursive: false}) { |
| 176 if (recursive && !parent.existsSync()) { | |
|
Anders Johnsen
2013/10/30 12:23:56
Ditto.
Bill Hesse
2013/10/30 15:07:37
Done.
| |
| 177 parent.createSync(recursive: true); | |
| 178 } | |
| 163 if (Platform.operatingSystem == 'windows') { | 179 if (Platform.operatingSystem == 'windows') { |
| 164 target = _makeWindowsLinkTarget(target); | 180 target = _makeWindowsLinkTarget(target); |
| 165 } | 181 } |
| 166 var result = _File._createLink(path, target); | 182 var result = _File._createLink(path, target); |
| 167 throwIfError(result, "Cannot create link", path); | 183 throwIfError(result, "Cannot create link", path); |
| 168 } | 184 } |
| 169 | 185 |
| 170 // Put target into the form "\??\C:\my\target\dir". | 186 // Put target into the form "\??\C:\my\target\dir". |
| 171 String _makeWindowsLinkTarget(String target) { | 187 String _makeWindowsLinkTarget(String target) { |
| 172 Uri base = new Uri.file('${Directory.current.path}\\'); | 188 Uri base = new Uri.file('${Directory.current.path}\\'); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 return new ArgumentError(); | 285 return new ArgumentError(); |
| 270 case _OSERROR_RESPONSE: | 286 case _OSERROR_RESPONSE: |
| 271 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], | 287 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], |
| 272 response[_OSERROR_RESPONSE_ERROR_CODE]); | 288 response[_OSERROR_RESPONSE_ERROR_CODE]); |
| 273 return new FileSystemException(message, path, err); | 289 return new FileSystemException(message, path, err); |
| 274 default: | 290 default: |
| 275 return new Exception("Unknown error"); | 291 return new Exception("Unknown error"); |
| 276 } | 292 } |
| 277 } | 293 } |
| 278 } | 294 } |
| OLD | NEW |