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

Unified Diff: tools/migration/lib/src/io.dart

Issue 2988973002: Better support for re-running in the middle of a migration. (Closed)
Patch Set: Better support for re-running in the middle of a migration. Created 3 years, 5 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 | « tools/migration/lib/src/fork.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/migration/lib/src/io.dart
diff --git a/tools/migration/lib/src/io.dart b/tools/migration/lib/src/io.dart
new file mode 100644
index 0000000000000000000000000000000000000000..83cb1bc5efb10139aab8e49deb9f60fcf530967e
--- /dev/null
+++ b/tools/migration/lib/src/io.dart
@@ -0,0 +1,58 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:io';
+
+import 'package:path/path.dart' as p;
+
+/// True if the file system should be left untouched.
+bool dryRun = false;
+
+final String sdkRoot =
+ p.normalize(p.join(p.dirname(p.fromUri(Platform.script)), '../../../'));
+
+final String testRoot = p.join(sdkRoot, "tests");
+
+/// Moves the file from [from] to [to], which are both assumed to be relative
+/// paths inside "tests".
+void moveFile(String from, String to) {
+ if (dryRun) {
+ print(" Dry run: move $from to $to");
+ return;
+ }
+
+ // Create the directory if needed.
+ new Directory(p.dirname(p.join(testRoot, to))).createSync(recursive: true);
+
+ new File(p.join(testRoot, from)).renameSync(p.join(testRoot, to));
+}
+
+/// Reads the contents of the file at [path], which is assumed to be relative
+/// within "tests".
+String readFile(String path) {
+ return new File(p.join(testRoot, path)).readAsStringSync();
+}
+
+/// Deletes the file at [path], which is assumed to be relative within "tests".
+void deleteFile(String path) {
+ if (dryRun) {
+ print(" Dry run: delete $path");
+ return;
+ }
+
+ new File(p.join(testRoot, path)).deleteSync();
+}
+
+/// Returns a list of the paths to all files within [dir], which is
+/// assumed to be relative to the SDK's "tests" directory and having file
+/// [extension].
+Iterable<String> listFiles(String dir, {String extension = ".dart"}) {
+ return new Directory(p.join(testRoot, dir))
+ .listSync(recursive: true)
+ .map((entry) {
+ if (!entry.path.endsWith(extension)) return null;
+
+ return entry.path;
+ }).where((path) => path != null);
+}
« no previous file with comments | « tools/migration/lib/src/fork.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698