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

Unified Diff: utils/pub/io.dart

Issue 12092080: Validate packages against their SDK constraints. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up a bit. Created 7 years, 11 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
Index: utils/pub/io.dart
diff --git a/utils/pub/io.dart b/utils/pub/io.dart
index 79f0a06524cc5b91b5e953fdf03d42ccb5b6ca82..e392fec3b4755ceac53af913f9abdf833c4992cd 100644
--- a/utils/pub/io.dart
+++ b/utils/pub/io.dart
@@ -69,6 +69,7 @@ Future<bool> fileExists(file) {
(exists) => "File $path ${exists ? 'exists' : 'does not exist'}.");
}
+// TODO(rnystrom): Get rid of this and only use sync.
/// Reads the contents of the text file [file], which can either be a [String]
/// or a [File].
Future<String> readTextFile(file) {
@@ -85,6 +86,23 @@ Future<String> readTextFile(file) {
});
}
+/// Reads the contents of the text file [file], which can either be a [String]
+/// or a [File].
+String readTextFileSync(file) {
nweiz 2013/01/31 22:38:53 I'm not a big fan of this intermediate duplication
Bob Nystrom 2013/02/01 16:53:29 Yup. Once that patch lands, this will be gone.
+ var path = _getPath(file);
+ log.io("Reading text file $path.");
+ var contents = new File(path).readAsStringSync(Encoding.UTF_8);
+
+ // Sanity check: don't spew a huge file.
+ if (contents.length < 1024 * 1024) {
+ log.fine("Read $path. Contents:\n$contents");
+ } else {
+ log.fine("Read ${contents.length} characters from $path.");
+ }
+
+ return contents;
+}
+
/// Creates [file] (which can either be a [String] or a [File]), and writes
/// [contents] to it. Completes when the file is written and closed.
///
@@ -289,6 +307,7 @@ Future<List<String>> listDir(dir,
return doList(_getDirectory(dir), new Set<String>());
}
+// TODO(rnystrom): Migrate everything over to the sync one and get rid of this.
/// Asynchronously determines if [dir], which can be a [String] directory path
/// or a [Directory], exists on the file system. Returns a [Future] that
/// completes with the result.
@@ -300,6 +319,11 @@ Future<bool> dirExists(dir) {
"${exists ? 'exists' : 'does not exist'}.");
}
+/// Determines if [dir], which can be a [String] directory path or a
+/// [Directory], exists on the file system. Returns a [Future] that completes
+/// with the result.
+bool dirExistsSync(dir) => _getDirectory(dir).existsSync();
+
/// "Cleans" [dir]. If that directory already exists, it will be deleted. Then a
/// new empty directory will be created. Returns a [Future] that completes when
/// the new clean directory is created.

Powered by Google App Engine
This is Rietveld 408576698