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

Side by Side Diff: sdk/lib/io/link.dart

Issue 23083002: dart:io | Add Link.update, and change Link.updateSync. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/standalone/io/link_async_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 * On other platforms, the posix symlink() call is used to make a symbolic 48 * On other platforms, the posix symlink() call is used to make a symbolic
49 * link containing the string [target]. If [target] is a relative path, 49 * link containing the string [target]. If [target] is a relative path,
50 * it will be interpreted relative to the directory containing the link. 50 * it will be interpreted relative to the directory containing the link.
51 */ 51 */
52 void createSync(String target); 52 void createSync(String target);
53 53
54 /** 54 /**
55 * Synchronously updates the link. Calling [updateSync] on a non-existing link 55 * Synchronously updates the link. Calling [updateSync] on a non-existing link
56 * will throw an exception. 56 * will throw an exception.
57 * 57 *
58 * If [linkRelative] is true, the target argument should be a relative path,
59 * and the link will interpret the target as a path relative to the link's
60 * directory.
61 *
62 * On the Windows platform, this will only work with directories, and the 58 * On the Windows platform, this will only work with directories, and the
63 * target directory must exist. 59 * target directory must exist.
64 */ 60 */
65 void updateSync(String target, {bool linkRelative: false }); 61 void updateSync(String target);
62
63 /**
64 * Updates the link. Returns a [:Future<Link>:] that completes with the
65 * link when it has been updated. Calling [update] on a non-existing link
66 * will complete its returned future with an exception.
67 *
68 * On the Windows platform, this will only work with directories, and the
69 * target directory must exist.
70 */
71 Future<Link> update(String target);
66 72
67 /** 73 /**
68 * Deletes the link. Returns a [:Future<Link>:] that completes with 74 * Deletes the link. Returns a [:Future<Link>:] that completes with
69 * the link when it has been deleted. This does not delete, or otherwise 75 * 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 76 * 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 77 * the link does not exist or is not actually a link, it completes the
72 * future with a LinkException. 78 * future with a LinkException.
73 */ 79 */
74 Future<Link> delete(); 80 Future<Link> delete();
75 81
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 if (target.length > 3 && target[1] == ':' && target[2] == '\\') { 197 if (target.length > 3 && target[1] == ':' && target[2] == '\\') {
192 target = '\\??\\$target'; 198 target = '\\??\\$target';
193 } else { 199 } else {
194 throw new LinkException( 200 throw new LinkException(
195 'Target $target of Link.create on Windows cannot be converted' + 201 'Target $target of Link.create on Windows cannot be converted' +
196 ' to start with a drive letter. Unexpected error.'); 202 ' to start with a drive letter. Unexpected error.');
197 } 203 }
198 return target; 204 return target;
199 } 205 }
200 206
201 void updateSync(String target, {bool linkRelative: false }) { 207 void updateSync(String target) {
202 // TODO(whesse): Replace with atomic update, where supported by platform. 208 // TODO(12414): Replace with atomic update, where supported by platform.
209 // Atomically changing a link can be done by creating the new link, with
210 // a different name, and using the rename() posix call to move it to
211 // the old name atomically.
203 deleteSync(); 212 deleteSync();
204 createSync(target); 213 createSync(target);
205 } 214 }
206 215
216 Future<Link> update(String target) {
217 // TODO(12414): Replace with atomic update, where supported by platform.
218 // Atomically changing a link can be done by creating the new link, with
219 // a different name, and using the rename() posix call to move it to
220 // the old name atomically.
221 return delete().then((_) => create(target));
222 }
223
207 Future<Link> delete() { 224 Future<Link> delete() {
208 _ensureFileService(); 225 _ensureFileService();
209 List request = new List(2); 226 List request = new List(2);
210 request[0] = _DELETE_LINK_REQUEST; 227 request[0] = _DELETE_LINK_REQUEST;
211 request[1] = path; 228 request[1] = path;
212 return _fileService.call(request).then((response) { 229 return _fileService.call(request).then((response) {
213 if (_isErrorResponse(response)) { 230 if (_isErrorResponse(response)) {
214 throw _exceptionFromResponse(response, "Cannot delete link", path); 231 throw _exceptionFromResponse(response, "Cannot delete link", path);
215 } 232 }
216 return this; 233 return this;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 if (path != null) { 332 if (path != null) {
316 sb.write(", path = $path"); 333 sb.write(", path = $path");
317 } 334 }
318 } 335 }
319 return sb.toString(); 336 return sb.toString();
320 } 337 }
321 final String message; 338 final String message;
322 final String path; 339 final String path;
323 final OSError osError; 340 final OSError osError;
324 } 341 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/link_async_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698