Make directory renaming more resilient on Windows.

BUG=

Review URL: https://codereview.chromium.org//11348332

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@15608 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
rnystrom@google.com 2012-11-30 22:39:45 +00:00
parent eef3848e9e
commit 2b3c4cd639
2 changed files with 26 additions and 6 deletions

View file

@ -315,7 +315,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

View file

@ -13,8 +13,3 @@
# TODO(nweiz): Figure out why this is failing.
[ $system == windows ]
pub_lish_test: Fail
# TODO(nweiz): The "pub lish" and oauth2 tests often fail mysteriously on
# Windows. See issues 7015 and 7016.
oauth2_test: Skip
curl_client_test: Skip