Chromium Code Reviews| Index: utils/pub/io.dart |
| diff --git a/utils/pub/io.dart b/utils/pub/io.dart |
| index 1d9b82416e3eb91b86e0ca41499e48134701fb7e..03888ab00edb59bbeecbf8cda7b48737dd18d9a0 100644 |
| --- a/utils/pub/io.dart |
| +++ b/utils/pub/io.dart |
| @@ -29,11 +29,13 @@ bool isBeneath(String entry, String dir) { |
| return !path.isAbsolute(relative) && path.split(relative)[0] != '..'; |
| } |
| -/// Determines if a file or directory at [path] exists. |
| -bool entryExists(String path) => fileExists(path) || dirExists(path); |
| +/// Determines if a file or directory exists at [path]. |
| +bool entryExists(String path) => dirExists(path) || fileExists(path); |
| -/// Determines if [file] exists on the file system. |
| -bool fileExists(String file) => new File(file).existsSync(); |
| +/// Determines if [file] exists on the file system. Will also return `true` if |
| +/// [file] points to a symlink, even a directory symlink. |
| +bool fileExists(String file) => |
| + new File(file).existsSync() || new Link(file).existsSync(); |
| /// Reads the contents of the text file [file]. |
| String readTextFile(String file) => |
| @@ -63,7 +65,13 @@ String writeTextFile(String file, String contents, {dontLogContents: false}) { |
| /// Deletes [file]. |
| void deleteFile(String file) { |
| - new File(file).deleteSync(); |
| + if (new Link(file).existsSync()) { |
| + // If it's a (possibly broken) symlink, handle that. |
| + return new Link(file).deleteSync(); |
| + } else { |
| + // Assume it's a normal file. |
| + new File(file).deleteSync(); |
|
nweiz
2013/03/15 21:00:17
This will actually work on symlinks.
Bob Nystrom
2013/03/15 22:06:56
Done.
|
| + } |
| } |
| /// Creates [file] and writes [contents] to it. |
| @@ -212,6 +220,10 @@ Future<String> cleanDir(String dir) { |
| if (dirExists(dir)) { |
| // Delete it first. |
| return deleteDir(dir).then((_) => createDir(dir)); |
| + } if (fileExists(dir)) { |
|
nweiz
2013/03/15 21:00:17
"else if"
Bob Nystrom
2013/03/15 22:06:56
Since those cases return anyway, reformatted and g
|
| + // If there is a non-directory there (file or symlink), delete it. |
| + deleteFile(dir); |
| + return createDir(dir); |
| } else { |
| // Just create it. |
| return createDir(dir); |