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

Unified Diff: frog/file_system_node.dart

Issue 8572044: Clean and create output directory when generating docs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. Created 9 years, 1 month 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 | « frog/file_system_dom.dart ('k') | frog/file_system_vm.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/file_system_node.dart
diff --git a/frog/file_system_node.dart b/frog/file_system_node.dart
index 33c2be162d9a2fe736e1c70c0b19af00e3ba5223..0c6f885aa4d1bdf04261441f54b970e981dc5d31 100644
--- a/frog/file_system_node.dart
+++ b/frog/file_system_node.dart
@@ -20,4 +20,64 @@ class NodeFileSystem implements FileSystem {
bool fileExists(String filename) {
return path.existsSync(filename);
}
+
+ void createDirectory(String path, [bool recursive = false]) {
+ if (!recursive) {
+ fs.mkdirSync(path);
+ return;
+ }
+
+ // See how much of the path already exists and how much we need to create.
+ final parts = path.split('/');
+ var existing = '.';
+ var part;
+ for (part = 0; part < parts.length; part++) {
+ final subpath = joinPaths(existing, parts[part]);
+
+ try {
+ final stat = fs.statSync(subpath);
+
+ if (stat.isDirectory()) {
+ existing = subpath;
+ } else {
+ throw 'Cannot create directory $path because $existing exists and ' +
+ 'is not a directory.';
+ }
+ } catch (e) {
+ // Ugly hack. We only want to catch ENOENT exceptions from fs.statSync
+ // which means the path we're trying doesn't exist. Since this is coming
+ // from node, we can't check the exception's type.
+ if (e.toString().indexOf('ENOENT', 0) != -1) break;
+
+ // Re-throw any other exceptions.
+ throw e;
+ }
+ }
+
+ // Create the remaining directories.
+ for (; part < parts.length; part++) {
+ existing = joinPaths(existing, parts[part]);
+ fs.mkdirSync(existing);
+ }
+ }
+
+ void removeDirectory(String path, [bool recursive = false]) {
+ if (recursive) {
+ // Remove the contents first.
+ for (final file in fs.readdirSync(path)) {
+ final subpath = joinPaths(path, file);
+ final stat = fs.statSync(subpath);
+
+ if (stat.isDirectory()) {
+ // Recurse into subdirectories.
+ removeDirectory(subpath, recursive: true);
+ } else if (stat.isFile()) {
+ // Try to remove the file.
+ fs.unlinkSync(subpath);
+ }
+ }
+ }
+
+ fs.rmdirSync(path);
+ }
}
« no previous file with comments | « frog/file_system_dom.dart ('k') | frog/file_system_vm.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698