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

Side by Side 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, 4 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 unified diff | Download patch
« no previous file with comments | « tools/migration/lib/src/fork.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:io';
6
7 import 'package:path/path.dart' as p;
8
9 /// True if the file system should be left untouched.
10 bool dryRun = false;
11
12 final String sdkRoot =
13 p.normalize(p.join(p.dirname(p.fromUri(Platform.script)), '../../../'));
14
15 final String testRoot = p.join(sdkRoot, "tests");
16
17 /// Moves the file from [from] to [to], which are both assumed to be relative
18 /// paths inside "tests".
19 void moveFile(String from, String to) {
20 if (dryRun) {
21 print(" Dry run: move $from to $to");
22 return;
23 }
24
25 // Create the directory if needed.
26 new Directory(p.dirname(p.join(testRoot, to))).createSync(recursive: true);
27
28 new File(p.join(testRoot, from)).renameSync(p.join(testRoot, to));
29 }
30
31 /// Reads the contents of the file at [path], which is assumed to be relative
32 /// within "tests".
33 String readFile(String path) {
34 return new File(p.join(testRoot, path)).readAsStringSync();
35 }
36
37 /// Deletes the file at [path], which is assumed to be relative within "tests".
38 void deleteFile(String path) {
39 if (dryRun) {
40 print(" Dry run: delete $path");
41 return;
42 }
43
44 new File(p.join(testRoot, path)).deleteSync();
45 }
46
47 /// Returns a list of the paths to all files within [dir], which is
48 /// assumed to be relative to the SDK's "tests" directory and having file
49 /// [extension].
50 Iterable<String> listFiles(String dir, {String extension = ".dart"}) {
51 return new Directory(p.join(testRoot, dir))
52 .listSync(recursive: true)
53 .map((entry) {
54 if (!entry.path.endsWith(extension)) return null;
55
56 return entry.path;
57 }).where((path) => path != null);
58 }
OLDNEW
« 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