Index: sdk/lib/io/link.dart |
diff --git a/sdk/lib/io/link.dart b/sdk/lib/io/link.dart |
index e8c4a4966826abb561e1feb0b078914c00bb5b86..abf6c202c2fdc8f243e8c44338c59e380020e70a 100644 |
--- a/sdk/lib/io/link.dart |
+++ b/sdk/lib/io/link.dart |
@@ -81,6 +81,26 @@ abstract class Link implements FileSystemEntity { |
void deleteSync(); |
/** |
+ * Renames this link. Returns a `Future<Link>` that completes |
+ * with a [Link] instance for the renamed link. |
+ * |
+ * If [newPath] identifies an existing link, that link is |
+ * replaced. If [newPath] identifies an existing file or directory, |
+ * the operation fails and the future completes with an exception. |
+ */ |
+ Future<Link> rename(String newPath); |
+ |
+ /** |
+ * Synchronously renames this link. Returns a [Link] |
+ * instance for the renamed link. |
+ * |
+ * If [newPath] identifies an existing link, that link is |
+ * replaced. If [newPath] identifies an existing file or directory |
+ * the operation fails and an exception is thrown. |
+ */ |
+ Link renameSync(String newPath); |
+ |
+ /** |
* Gets the target of the link. Returns a future that completes with |
* the path to the target. |
* |
@@ -195,6 +215,27 @@ class _Link extends FileSystemEntity implements Link { |
throwIfError(result, "Cannot delete link", path); |
} |
+ Future<Link> rename(String newPath) { |
+ _ensureFileService(); |
+ List request = new List(3); |
+ request[0] = _RENAME_LINK_REQUEST; |
+ request[1] = path; |
+ request[2] = newPath; |
+ return _fileService.call(request).then((response) { |
+ if (_isErrorResponse(response)) { |
+ throw _exceptionFromResponse( |
+ response, "Cannot rename link '$_path' to '$newPath'"); |
+ } |
+ return new Link(newPath); |
+ }); |
+ } |
+ |
+ Link renameSync(String newPath) { |
+ var result = _File._renameLink(path, newPath); |
+ throwIfError(result, "Cannot rename link '$path' to '$newPath'"); |
+ return new Link(newPath); |
+ } |
+ |
Future<String> target() { |
_ensureFileService(); |
List request = new List(2); |