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

Unified Diff: utils/pub/io.dart

Issue 13132002: Version 0.4.3.5 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: 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/oauth2.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/io.dart
===================================================================
--- utils/pub/io.dart (revision 20601)
+++ utils/pub/io.dart (working copy)
@@ -28,13 +28,17 @@
}
/// Determines if a file or directory exists at [path].
-bool entryExists(String path) => dirExists(path) || fileExists(path);
+bool entryExists(String path) =>
+ dirExists(path) || fileExists(path) || linkExists(path);
-/// 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();
+/// Returns whether [link] exists on the file system. This will return `true`
+/// for any symlink, regardless of what it points at or whether it's broken.
+bool linkExists(String path) => new Link(path).existsSync();
+/// Returns whether [file] exists on the file system. This will return `true`
+/// for a symlink only if that symlink is unbroken and points to a file.
+bool fileExists(String file) => new File(file).existsSync();
+
/// Reads the contents of the text file [file].
String readTextFile(String file) =>
new File(file).readAsStringSync(encoding: Encoding.UTF_8);
@@ -61,11 +65,6 @@
return file;
}
-/// Deletes [file].
-void deleteFile(String file) {
- new File(file).deleteSync();
-}
-
/// Creates [file] and writes [contents] to it.
String writeBinaryFile(String file, List<int> contents) {
log.io("Writing ${contents.length} bytes to binary file $file.");
@@ -126,12 +125,6 @@
return tempDir.path;
}
-/// 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
/// subdirectory contents (defaults to `false`). If [includeHiddenFiles] is
/// `true`, includes files and directories beginning with `.` (defaults to
@@ -199,21 +192,34 @@
return doList(dir, new Set<String>());
}
-/// Determines if [dir] exists on the file system.
+/// Returns whether [dir] exists on the file system. This will return `true` for
+/// a symlink only if that symlink is unbroken and points to a directory.
bool dirExists(String dir) => new Directory(dir).existsSync();
+/// Deletes whatever's at [path], whether it's a file, directory, or symlink. If
+/// it's a directory, it will be deleted recursively.
+void deleteEntry(String path) {
+ if (linkExists(path)) {
+ log.io("Deleting link $path.");
+ if (Platform.operatingSystem == 'windows') {
+ // TODO(nweiz): remove this when issue 9278 is fixed.
+ new Directory(path).deleteSync();
+ } else {
+ new Link(path).deleteSync();
+ }
+ } else if (dirExists(path)) {
+ log.io("Deleting directory $path.");
+ new Directory(path).deleteSync(recursive: true);
+ } else {
+ log.io("Deleting file $path.");
+ new File(path).deleteSync();
+ }
+}
+
/// "Cleans" [dir]. If that directory already exists, it will be deleted. Then a
/// 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.
+ if (entryExists(dir)) deleteEntry(dir);
createDir(dir);
}
@@ -582,7 +588,7 @@
return defer(() {
var tempDir = createTempDir();
return new Future.of(() => fn(tempDir))
- .whenComplete(() => deleteDir(tempDir));
+ .whenComplete(() => deleteEntry(tempDir));
});
}
« no previous file with comments | « utils/pub/entrypoint.dart ('k') | utils/pub/oauth2.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698