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

Unified Diff: runtime/bin/directory_impl.dart

Issue 8934004: Add support for getting OS error information for creating temporary directories (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated test Created 9 years 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: runtime/bin/directory_impl.dart
diff --git a/runtime/bin/directory_impl.dart b/runtime/bin/directory_impl.dart
index e87cb540c64eb1911cdba87fc4bc575bf3531f5f..5cc0a676fefb7db5142615bef49c2dcae2947bfa 100644
--- a/runtime/bin/directory_impl.dart
+++ b/runtime/bin/directory_impl.dart
@@ -3,6 +3,12 @@
// BSD-style license that can be found in the LICENSE file.
+class _OSStatus {
+ int _errorCode; // Set to OS error code if process start failed.
Bill Hesse 2011/12/13 13:51:03 _OSStatus is no longer just used for process start
Søren Gjesse 2011/12/13 14:07:40 This creates _OSStatus and keeps _ProcessStartStat
+ String _errorMessage; // Set to OS error message if process start failed.
+}
+
+
class _DirectoryListingIsolate extends Isolate {
_DirectoryListingIsolate() : super.heavy();
@@ -36,7 +42,15 @@ class _DirectoryCreateTempIsolate extends Isolate {
void main() {
port.receive((path, replyTo) {
// Call function to get file name
- replyTo.send(_Directory._createTemp(path, (Math.random() * 0x8000000).toInt()));
+ var status = new _OSStatus();
+ var result = _Directory._createTemp(path,
+ (Math.random() * 0x8000000).toInt(),
+ status);
+ if (result == null) {
+ replyTo.send(status);
Bill Hesse 2011/12/13 13:51:03 Can we send arbitrary objects between isolates now
Søren Gjesse 2011/12/13 14:07:40 I surely hope so. The tests work.
+ } else {
+ replyTo.send(result);
+ }
port.close();
});
}
@@ -47,7 +61,9 @@ class _Directory implements Directory {
_Directory(String this._path);
- static String _createTemp(String template, int num) native "Directory_CreateTemp";
+ static String _createTemp(String template,
+ int num,
+ _OSStatus status) native "Directory_CreateTemp";
bool existsSync() {
int exists = _exists(_path);
@@ -66,14 +82,15 @@ class _Directory implements Directory {
void createTemp() {
new _DirectoryCreateTempIsolate().spawn().then((port) {
port.call(_path).receive((result, ignored) {
- if (result != '') {
+ if (result is !_OSStatus) {
_path = result;
if (_createTempHandler !== null) {
_createTempHandler();
}
} else {
if (_errorHandler !== null) {
- _errorHandler("Could not create temporary directory: $_path");
+ _errorHandler("Could not create temporary directory: " +
+ "${result._errorMessage}");
}
}
});
@@ -81,11 +98,12 @@ class _Directory implements Directory {
}
void createTempSync() {
- var result = _createTemp(path, (Math.random() * 0x8000000).toInt());
- if (result != '') {
+ var status = new _OSStatus();
+ var result = _createTemp(path, (Math.random() * 0x8000000).toInt(), status);
+ if (result != null) {
_path = result;
} else {
- throw "createTempSync failed";
+ throw new DirectoryException(status._errorMessage, status._errorCode);
}
}

Powered by Google App Engine
This is Rietveld 408576698