| 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 */ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 * Updates the link. Returns a [:Future<Link>:] that completes with the | 58 * Updates the link. Returns a [:Future<Link>:] that completes with the |
| 59 * link when it has been updated. Calling [update] on a non-existing link | 59 * link when it has been updated. Calling [update] on a non-existing link |
| 60 * will complete its returned future with an exception. | 60 * will complete its returned future with an exception. |
| 61 * | 61 * |
| 62 * On the Windows platform, this will only work with directories, and the | 62 * On the Windows platform, this will only work with directories, and the |
| 63 * target directory must exist. | 63 * target directory must exist. |
| 64 */ | 64 */ |
| 65 Future<Link> update(String target); | 65 Future<Link> update(String target); |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Deletes the link. Returns a [:Future<Link>:] that completes with | |
| 69 * the link when it has been deleted. This does not delete, or otherwise | |
| 70 * affect, the target of the link. It also works on broken links, but if | |
| 71 * the link does not exist or is not actually a link, it completes the | |
| 72 * future with a LinkException. | |
| 73 */ | |
| 74 Future<Link> delete(); | |
| 75 | |
| 76 /** | |
| 77 * Synchronously deletes the link. This does not delete, or otherwise | |
| 78 * affect, the target of the link. It also works on broken links, but if | |
| 79 * the link does not exist or is not actually a link, it throws a | |
| 80 * LinkException. | |
| 81 */ | |
| 82 void deleteSync(); | |
| 83 | |
| 84 /** | |
| 85 * Renames this link. Returns a `Future<Link>` that completes | 68 * Renames this link. Returns a `Future<Link>` that completes |
| 86 * with a [Link] instance for the renamed link. | 69 * with a [Link] instance for the renamed link. |
| 87 * | 70 * |
| 88 * If [newPath] identifies an existing link, that link is | 71 * If [newPath] identifies an existing link, that link is |
| 89 * replaced. If [newPath] identifies an existing file or directory, | 72 * replaced. If [newPath] identifies an existing file or directory, |
| 90 * the operation fails and the future completes with an exception. | 73 * the operation fails and the future completes with an exception. |
| 91 */ | 74 */ |
| 92 Future<Link> rename(String newPath); | 75 Future<Link> rename(String newPath); |
| 93 | 76 |
| 94 /** | 77 /** |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 189 } |
| 207 | 190 |
| 208 Future<Link> update(String target) { | 191 Future<Link> update(String target) { |
| 209 // TODO(12414): Replace with atomic update, where supported by platform. | 192 // TODO(12414): Replace with atomic update, where supported by platform. |
| 210 // Atomically changing a link can be done by creating the new link, with | 193 // Atomically changing a link can be done by creating the new link, with |
| 211 // a different name, and using the rename() posix call to move it to | 194 // a different name, and using the rename() posix call to move it to |
| 212 // the old name atomically. | 195 // the old name atomically. |
| 213 return delete().then((_) => create(target)); | 196 return delete().then((_) => create(target)); |
| 214 } | 197 } |
| 215 | 198 |
| 216 Future<Link> delete() { | 199 Future<Link> _delete({bool recursive: false}) { |
| 200 if (recursive) { |
| 201 return new Directory(path).delete(recursive: true).then((_) => this); |
| 202 } |
| 217 _ensureFileService(); | 203 _ensureFileService(); |
| 218 List request = new List(2); | 204 List request = new List(2); |
| 219 request[0] = _DELETE_LINK_REQUEST; | 205 request[0] = _DELETE_LINK_REQUEST; |
| 220 request[1] = path; | 206 request[1] = path; |
| 221 return _fileService.call(request).then((response) { | 207 return _fileService.call(request).then((response) { |
| 222 if (_isErrorResponse(response)) { | 208 if (_isErrorResponse(response)) { |
| 223 throw _exceptionFromResponse(response, "Cannot delete link", path); | 209 throw _exceptionFromResponse(response, "Cannot delete link", path); |
| 224 } | 210 } |
| 225 return this; | 211 return this; |
| 226 }); | 212 }); |
| 227 } | 213 } |
| 228 | 214 |
| 229 void deleteSync() { | 215 void _deleteSync({bool recursive: false}) { |
| 230 var result = _File._deleteLink(path); | 216 if (recursive) { |
| 217 return new Directory(path).deleteSync(recursive: true); |
| 218 } |
| 219 var result = _File._deleteLinkNative(path); |
| 231 throwIfError(result, "Cannot delete link", path); | 220 throwIfError(result, "Cannot delete link", path); |
| 232 } | 221 } |
| 233 | 222 |
| 234 Future<Link> rename(String newPath) { | 223 Future<Link> rename(String newPath) { |
| 235 _ensureFileService(); | 224 _ensureFileService(); |
| 236 List request = new List(3); | 225 List request = new List(3); |
| 237 request[0] = _RENAME_LINK_REQUEST; | 226 request[0] = _RENAME_LINK_REQUEST; |
| 238 request[1] = path; | 227 request[1] = path; |
| 239 request[2] = newPath; | 228 request[2] = newPath; |
| 240 return _fileService.call(request).then((response) { | 229 return _fileService.call(request).then((response) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 if (path != null) { | 313 if (path != null) { |
| 325 sb.write(", path = $path"); | 314 sb.write(", path = $path"); |
| 326 } | 315 } |
| 327 } | 316 } |
| 328 return sb.toString(); | 317 return sb.toString(); |
| 329 } | 318 } |
| 330 final String message; | 319 final String message; |
| 331 final String path; | 320 final String path; |
| 332 final OSError osError; | 321 final OSError osError; |
| 333 } | 322 } |
| OLD | NEW |