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

Unified Diff: runtime/bin/directory_impl.dart

Issue 8588029: Add Directory.createTemp() to asynchronously create a temporary directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Avoid test failures if /tmp does not exist. 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 | « runtime/bin/directory.dart ('k') | runtime/bin/directory_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_impl.dart
diff --git a/runtime/bin/directory_impl.dart b/runtime/bin/directory_impl.dart
index 485dfadfcac5e6b83b22824b6f9ee4ff70552399..ee4cbaa9c04282743e4d22ff3b1f4e0803a1a256 100644
--- a/runtime/bin/directory_impl.dart
+++ b/runtime/bin/directory_impl.dart
@@ -29,6 +29,22 @@ class _DirectoryListingIsolate extends Isolate {
}
+class _DirectoryCreateTempIsolate extends Isolate {
+
+ _DirectoryCreateTempIsolate() : super.heavy();
+
+ void main() {
+ port.receive((path, replyTo) {
+ // Call function to get file name
+ replyTo.send(_createTemp(path, (Math.random() * 0x8000000).toInt()));
+ port.close();
+ });
+ }
+
+ String _createTemp(String template, int num) native "Directory_CreateTemp";
+}
+
+
class _Directory implements Directory {
_Directory(String this._path);
@@ -47,6 +63,23 @@ class _Directory implements Directory {
}
}
+ void createTemp() {
+ new _DirectoryCreateTempIsolate().spawn().then((port) {
+ port.call(_path).receive((result, ignored) {
+ if (result != '') {
+ _path = result;
+ if (_createTempHandler !== null) {
+ _createTempHandler();
+ }
+ } else {
+ if (_errorHandler !== null) {
+ _errorHandler("Could not create temporary directory: $_path");
+ }
+ }
+ });
+ });
+ }
+
void deleteSync() {
if (!_delete(_path)) {
throw new DirectoryException("Directory deletion failed: $_path");
@@ -129,6 +162,10 @@ class _Directory implements Directory {
_doneHandler = doneHandler;
}
+ void set createTempHandler(void createTempHandler()) {
+ _createTempHandler = createTempHandler;
+ }
+
void set errorHandler(void errorHandler(String error)) {
_errorHandler = errorHandler;
}
@@ -148,6 +185,7 @@ class _Directory implements Directory {
var _dirHandler;
var _fileHandler;
var _doneHandler;
+ var _createTempHandler;
var _errorHandler;
String _path;
« no previous file with comments | « runtime/bin/directory.dart ('k') | runtime/bin/directory_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698