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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 5
6 class _OSStatus {
7 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
8 String _errorMessage; // Set to OS error message if process start failed.
9 }
10
11
6 class _DirectoryListingIsolate extends Isolate { 12 class _DirectoryListingIsolate extends Isolate {
7 13
8 _DirectoryListingIsolate() : super.heavy(); 14 _DirectoryListingIsolate() : super.heavy();
9 15
10 void main() { 16 void main() {
11 port.receive((message, replyTo) { 17 port.receive((message, replyTo) {
12 bool started = _list(message['dir'], 18 bool started = _list(message['dir'],
13 message['recursive'], 19 message['recursive'],
14 message['dirPort'], 20 message['dirPort'],
15 message['filePort'], 21 message['filePort'],
(...skipping 13 matching lines...) Expand all
29 } 35 }
30 36
31 37
32 class _DirectoryCreateTempIsolate extends Isolate { 38 class _DirectoryCreateTempIsolate extends Isolate {
33 39
34 _DirectoryCreateTempIsolate() : super.heavy(); 40 _DirectoryCreateTempIsolate() : super.heavy();
35 41
36 void main() { 42 void main() {
37 port.receive((path, replyTo) { 43 port.receive((path, replyTo) {
38 // Call function to get file name 44 // Call function to get file name
39 replyTo.send(_Directory._createTemp(path, (Math.random() * 0x8000000).toIn t())); 45 var status = new _OSStatus();
46 var result = _Directory._createTemp(path,
47 (Math.random() * 0x8000000).toInt(),
48 status);
49 if (result == null) {
50 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.
51 } else {
52 replyTo.send(result);
53 }
40 port.close(); 54 port.close();
41 }); 55 });
42 } 56 }
43 } 57 }
44 58
45 59
46 class _Directory implements Directory { 60 class _Directory implements Directory {
47 61
48 _Directory(String this._path); 62 _Directory(String this._path);
49 63
50 static String _createTemp(String template, int num) native "Directory_CreateTe mp"; 64 static String _createTemp(String template,
65 int num,
66 _OSStatus status) native "Directory_CreateTemp";
51 67
52 bool existsSync() { 68 bool existsSync() {
53 int exists = _exists(_path); 69 int exists = _exists(_path);
54 if (exists < 0) { 70 if (exists < 0) {
55 throw new DirectoryException("Diretory exists test failed: $_path"); 71 throw new DirectoryException("Diretory exists test failed: $_path");
56 } 72 }
57 return (exists == 1); 73 return (exists == 1);
58 } 74 }
59 75
60 void createSync() { 76 void createSync() {
61 if (!_create(_path)) { 77 if (!_create(_path)) {
62 throw new DirectoryException("Directory creation failed: $_path"); 78 throw new DirectoryException("Directory creation failed: $_path");
63 } 79 }
64 } 80 }
65 81
66 void createTemp() { 82 void createTemp() {
67 new _DirectoryCreateTempIsolate().spawn().then((port) { 83 new _DirectoryCreateTempIsolate().spawn().then((port) {
68 port.call(_path).receive((result, ignored) { 84 port.call(_path).receive((result, ignored) {
69 if (result != '') { 85 if (result is !_OSStatus) {
70 _path = result; 86 _path = result;
71 if (_createTempHandler !== null) { 87 if (_createTempHandler !== null) {
72 _createTempHandler(); 88 _createTempHandler();
73 } 89 }
74 } else { 90 } else {
75 if (_errorHandler !== null) { 91 if (_errorHandler !== null) {
76 _errorHandler("Could not create temporary directory: $_path"); 92 _errorHandler("Could not create temporary directory: " +
93 "${result._errorMessage}");
77 } 94 }
78 } 95 }
79 }); 96 });
80 }); 97 });
81 } 98 }
82 99
83 void createTempSync() { 100 void createTempSync() {
84 var result = _createTemp(path, (Math.random() * 0x8000000).toInt()); 101 var status = new _OSStatus();
85 if (result != '') { 102 var result = _createTemp(path, (Math.random() * 0x8000000).toInt(), status);
103 if (result != null) {
86 _path = result; 104 _path = result;
87 } else { 105 } else {
88 throw "createTempSync failed"; 106 throw new DirectoryException(status._errorMessage, status._errorCode);
89 } 107 }
90 } 108 }
91 109
92 void deleteSync() { 110 void deleteSync() {
93 if (!_delete(_path)) { 111 if (!_delete(_path)) {
94 throw new DirectoryException("Directory deletion failed: $_path"); 112 throw new DirectoryException("Directory deletion failed: $_path");
95 } 113 }
96 } 114 }
97 115
98 void list([bool recursive = false]) { 116 void list([bool recursive = false]) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 bool _delete(String path) native "Directory_Delete"; 210 bool _delete(String path) native "Directory_Delete";
193 211
194 var _dirHandler; 212 var _dirHandler;
195 var _fileHandler; 213 var _fileHandler;
196 var _doneHandler; 214 var _doneHandler;
197 var _createTempHandler; 215 var _createTempHandler;
198 var _errorHandler; 216 var _errorHandler;
199 217
200 String _path; 218 String _path;
201 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698