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

Unified Diff: utils/pub/io.dart

Issue 12772005: Handle broken symlinks when creating package dirs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 9 months 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 | « utils/pub/entrypoint.dart ('k') | utils/pub/path_source.dart » ('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 1d9b82416e3eb91b86e0ca41499e48134701fb7e..3f54fcdd915cac4bc05e4dafd5d77f119ff3c5b8 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) =>
@@ -212,10 +214,16 @@ Future<String> cleanDir(String dir) {
if (dirExists(dir)) {
// Delete it first.
return deleteDir(dir).then((_) => createDir(dir));
- } else {
- // Just create it.
+ }
+
+ if (fileExists(dir)) {
+ // If there is a non-directory there (file or symlink), delete it.
+ deleteFile(dir);
return createDir(dir);
}
+
+ // Just create it.
+ return createDir(dir);
});
}
« no previous file with comments | « utils/pub/entrypoint.dart ('k') | utils/pub/path_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698