Chromium Code Reviews| Index: utils/pub/io.dart |
| diff --git a/utils/pub/io.dart b/utils/pub/io.dart |
| index 381889db264a782c8a144fcb99dd9c5927f385b4..5cca45f8c60f986c72abc202127535493e03ee4e 100644 |
| --- a/utils/pub/io.dart |
| +++ b/utils/pub/io.dart |
| @@ -128,12 +128,10 @@ String createTempDir([dir = '']) { |
| return tempDir.path; |
| } |
| -// TODO(nweiz): Remove this when issue 9252 is fixed. |
| -/// Asynchronously recursively deletes [dir]. Returns a [Future] that completes |
| -/// when the deletion is done. |
| -Future<String> deleteDir(String dir) { |
| - return _attemptRetryable(() => log.ioAsync("delete directory $dir", |
| - new Directory(dir).delete(recursive: true).then((_) => dir))); |
| +/// Recursively deletes [dir]. |
| +void deleteDir(String dir) { |
| + log.io("Deleting directory $dir."); |
| + new Directory(dir).deleteSync(recursive: true); |
| } |
| /// Asynchronously lists the contents of [dir]. If [recursive] is `true`, lists |
| @@ -208,66 +206,24 @@ Future<List<String>> listDir(String dir, |
| bool dirExists(String dir) => new Directory(dir).existsSync(); |
| /// "Cleans" [dir]. If that directory already exists, it will be deleted. Then a |
| -/// new empty directory will be created. Returns a [Future] that completes when |
| -/// the new clean directory is created. |
| -Future<String> cleanDir(String dir) { |
| - return defer(() { |
| - if (dirExists(dir)) { |
| - // Delete it first. |
| - return deleteDir(dir).then((_) => createDir(dir)); |
| - } |
| - |
| - if (fileExists(dir)) { |
| - // If there is a non-directory there (file or symlink), delete it. |
| - deleteFile(dir); |
| - return createDir(dir); |
| - } |
| +/// new empty directory will be created. |
| +void cleanDir(String dir) { |
| + if (dirExists(dir)) { |
| + // Delete it first. |
| + deleteDir(dir); |
| + } else if (fileExists(dir)) { |
| + // If there is a non-directory there (file or symlink), delete it. |
| + deleteFile(dir); |
| + } |
| - // Just create it. |
| - return createDir(dir); |
| - }); |
| + // Just create it. |
| + createDir(dir); |
| } |
| -// TODO(nweiz): remove this when issue 9253 is fixed. |
| -/// Renames (i.e. moves) the directory [from] to [to]. Returns a [Future] with |
| -/// the destination directory. |
| -Future<String> renameDir(String from, String to) { |
| +/// Renames (i.e. moves) the directory [from] to [to]. |
| +void renameDir(String from, String to) { |
| log.io("Renaming directory $from to $to."); |
| - |
| - return _attemptRetryable(() => new Directory(from).rename(to)).then((dir) { |
| - log.fine("Renamed directory $from to $to."); |
| - return to; |
| - }); |
| -} |
| - |
| -/// On Windows, we sometimes get failures where the directory is still in use |
| -/// when we try to do something with it. This is usually because the OS hasn't |
| -/// noticed yet that a process using that directory has closed. To be a bit |
| -/// more resilient, we wait and retry a few times. |
| -/// |
| -/// Takes a [callback] which returns a future for the operation being attempted. |
| -/// If that future completes with an error, it will slepp and then [callback] |
| -/// will be invoked again to retry the operation. It will try a few times before |
| -/// giving up. |
| -Future _attemptRetryable(Future callback()) { |
| - // Only do lame retry logic on Windows. |
| - if (Platform.operatingSystem != 'windows') return callback(); |
| - |
| - var attempts = 0; |
| - makeAttempt(_) { |
| - attempts++; |
| - return callback().catchError((e) { |
| - if (attempts >= 10) { |
| - throw 'Could not complete operation. Gave up after $attempts attempts.'; |
| - } |
| - |
| - // Wait a bit and try again. |
| - log.fine("Operation failed, retrying (attempt $attempts)."); |
| - return sleep(500).then(makeAttempt); |
| - }); |
| - } |
| - |
| - return makeAttempt(null); |
| + new Directory(from).renameSync(to); |
| } |
| /// Creates a new symlink at path [symlink] that points to [target]. Returns a |
| @@ -627,9 +583,8 @@ Future timeout(Future input, int milliseconds, String description) { |
| Future withTempDir(Future fn(String path)) { |
| return defer(() { |
| var tempDir = createTempDir(); |
| - return fn(tempDir).whenComplete(() { |
| - return deleteDir(tempDir); |
| - }); |
| + return new Future.of(() => fn(tempDir)) |
|
Bob Nystrom
2013/03/20 16:33:42
What's this change for? Is it just to handle fn()
nweiz
2013/03/20 19:45:46
Yes; I think we should have the general heuristic
Bob Nystrom
2013/03/20 19:49:34
I think the way I tend to approach this is to just
|
| + .whenComplete(() => deleteDir(tempDir)); |
| }); |
| } |