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

Unified 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, 1 month 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 | « no previous file | utils/tests/pub/pub.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/io.dart
diff --git a/utils/pub/io.dart b/utils/pub/io.dart
index 0c6903f19483ed0f3ecb276ca251f902be2cc5dc..dfb8f4500bbda929378b1fb7e9b18c7d7df80770 100644
--- a/utils/pub/io.dart
+++ b/utils/pub/io.dart
@@ -309,7 +309,32 @@ Future<Directory> cleanDir(dir) {
/// Renames (i.e. moves) the directory [from] to [to]. Returns a [Future] with
/// the destination directory.
-Future<Directory> renameDir(from, String to) =>_getDirectory(from).rename(to);
+Future<Directory> renameDir(from, String to) {
+ from = _getDirectory(from);
+
+ if (Platform.operatingSystem != 'windows') return from.rename(to);
+
+ // On Windows, we sometimes get failures where the directory is still in use
+ // when we try to move it. To be a bit more resilient, we wait and retry a
+ // few times.
+ var attempts = 0;
+ attemptRename(_) {
+ attempts++;
+ return from.rename(to).transformException((e) {
+ if (attempts >= 10) {
+ throw 'Could not move directory "${from.path}" to "$to". Gave up '
+ 'after $attempts attempts.';
+ }
+
+ // Wait a bit and try again.
+ return sleep(500).chain(attemptRename);
+ });
+
+ return from;
+ }
+
+ return attemptRename(null);
+}
/**
* Creates a new symlink that creates an alias from [from] to [to], both of
« 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