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

Side by Side Diff: utils/pub/io.dart

Issue 11348332: Make directory renaming more resilient on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Only retry on Windows. Created 8 years 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 | utils/tests/pub/pub.status » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * Helper functionality to make working with IO easier. 6 * Helper functionality to make working with IO easier.
7 */ 7 */
8 library io; 8 library io;
9 9
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return deleteDir(dir).chain((_) => createDir(dir)); 302 return deleteDir(dir).chain((_) => createDir(dir));
303 } else { 303 } else {
304 // Just create it. 304 // Just create it.
305 return createDir(dir); 305 return createDir(dir);
306 } 306 }
307 }); 307 });
308 } 308 }
309 309
310 /// Renames (i.e. moves) the directory [from] to [to]. Returns a [Future] with 310 /// Renames (i.e. moves) the directory [from] to [to]. Returns a [Future] with
311 /// the destination directory. 311 /// the destination directory.
312 Future<Directory> renameDir(from, String to) =>_getDirectory(from).rename(to); 312 Future<Directory> renameDir(from, String to) {
313 from = _getDirectory(from);
314
315 if (Platform.operatingSystem != 'windows') return from.rename(to);
316
317 // On Windows, we sometimes get failures where the directory is still in use
318 // when we try to move it. To be a bit more resilient, we wait and retry a
319 // few times.
320 var attempts = 0;
321 attemptRename(_) {
322 attempts++;
323 return from.rename(to).transformException((e) {
324 if (attempts >= 10) {
325 throw 'Could not move directory "${from.path}" to "$to". Gave up '
326 'after $attempts attempts.';
327 }
328
329 // Wait a bit and try again.
330 return sleep(500).chain(attemptRename);
331 });
332
333 return from;
334 }
335
336 return attemptRename(null);
337 }
313 338
314 /** 339 /**
315 * Creates a new symlink that creates an alias from [from] to [to], both of 340 * Creates a new symlink that creates an alias from [from] to [to], both of
316 * which can be a [String], [File], or [Directory]. Returns a [Future] which 341 * which can be a [String], [File], or [Directory]. Returns a [Future] which
317 * completes to the symlink file (i.e. [to]). 342 * completes to the symlink file (i.e. [to]).
318 */ 343 */
319 Future<File> createSymlink(from, to) { 344 Future<File> createSymlink(from, to) {
320 from = _getPath(from); 345 from = _getPath(from);
321 to = _getPath(to); 346 to = _getPath(to);
322 347
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 return new Directory(entry); 990 return new Directory(entry);
966 } 991 }
967 992
968 /** 993 /**
969 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. 994 * Gets a [Uri] for [uri], which can either already be one, or be a [String].
970 */ 995 */
971 Uri _getUri(uri) { 996 Uri _getUri(uri) {
972 if (uri is Uri) return uri; 997 if (uri is Uri) return uri;
973 return new Uri.fromString(uri); 998 return new Uri.fromString(uri);
974 } 999 }
OLDNEW
« no previous file with comments | « no previous file | utils/tests/pub/pub.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698