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

Unified Diff: sdk/lib/io/link.dart

Issue 17848003: dart:io | Add rename to Link (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix again Created 7 years, 6 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/link_async_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 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);
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | tests/standalone/io/link_async_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698