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

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: Added path to exception messages 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
« no previous file with comments | « runtime/bin/directory.dart ('k') | runtime/bin/directory_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Used for holding error code and error message for failed OS system calls.
7 class _OSStatus {
8 int _errorCode;
9 String _errorMessage;
10 }
11
12
6 class _DirectoryListingIsolate extends Isolate { 13 class _DirectoryListingIsolate extends Isolate {
7 14
8 _DirectoryListingIsolate() : super.heavy(); 15 _DirectoryListingIsolate() : super.heavy();
9 16
10 void main() { 17 void main() {
11 port.receive((message, replyTo) { 18 port.receive((message, replyTo) {
12 bool started = _list(message['dir'], 19 bool started = _list(message['dir'],
13 message['recursive'], 20 message['recursive'],
14 message['dirPort'], 21 message['dirPort'],
15 message['filePort'], 22 message['filePort'],
(...skipping 13 matching lines...) Expand all
29 } 36 }
30 37
31 38
32 class _DirectoryCreateTempIsolate extends Isolate { 39 class _DirectoryCreateTempIsolate extends Isolate {
33 40
34 _DirectoryCreateTempIsolate() : super.heavy(); 41 _DirectoryCreateTempIsolate() : super.heavy();
35 42
36 void main() { 43 void main() {
37 port.receive((path, replyTo) { 44 port.receive((path, replyTo) {
38 // Call function to get file name 45 // Call function to get file name
39 replyTo.send(_Directory._createTemp(path, (Math.random() * 0x8000000).toIn t())); 46 var status = new _OSStatus();
47 var result = _Directory._createTemp(path,
48 (Math.random() * 0x8000000).toInt(),
49 status);
50 if (result == null) {
51 replyTo.send(status);
52 } else {
53 replyTo.send(result);
54 }
40 port.close(); 55 port.close();
41 }); 56 });
42 } 57 }
43 } 58 }
44 59
45 60
46 class _Directory implements Directory { 61 class _Directory implements Directory {
47 62
48 _Directory(String this._path); 63 _Directory(String this._path);
49 64
50 static String _createTemp(String template, int num) native "Directory_CreateTe mp"; 65 static String _createTemp(String template,
66 int num,
67 _OSStatus status) native "Directory_CreateTemp";
51 68
52 bool existsSync() { 69 bool existsSync() {
53 int exists = _exists(_path); 70 int exists = _exists(_path);
54 if (exists < 0) { 71 if (exists < 0) {
55 throw new DirectoryException("Diretory exists test failed: $_path"); 72 throw new DirectoryException("Diretory exists test failed: $_path");
56 } 73 }
57 return (exists == 1); 74 return (exists == 1);
58 } 75 }
59 76
60 void createSync() { 77 void createSync() {
61 if (!_create(_path)) { 78 if (!_create(_path)) {
62 throw new DirectoryException("Directory creation failed: $_path"); 79 throw new DirectoryException("Directory creation failed: $_path");
63 } 80 }
64 } 81 }
65 82
66 void createTemp() { 83 void createTemp() {
67 new _DirectoryCreateTempIsolate().spawn().then((port) { 84 new _DirectoryCreateTempIsolate().spawn().then((port) {
68 port.call(_path).receive((result, ignored) { 85 port.call(_path).receive((result, ignored) {
69 if (result != '') { 86 if (result is !_OSStatus) {
70 _path = result; 87 _path = result;
71 if (_createTempHandler !== null) { 88 if (_createTempHandler !== null) {
72 _createTempHandler(); 89 _createTempHandler();
73 } 90 }
74 } else { 91 } else {
75 if (_errorHandler !== null) { 92 if (_errorHandler !== null) {
76 _errorHandler("Could not create temporary directory: $_path"); 93 _errorHandler("Could not create temporary directory [$_path]: " +
94 "${result._errorMessage}");
77 } 95 }
78 } 96 }
79 }); 97 });
80 }); 98 });
81 } 99 }
82 100
83 void createTempSync() { 101 void createTempSync() {
84 var result = _createTemp(path, (Math.random() * 0x8000000).toInt()); 102 var status = new _OSStatus();
85 if (result != '') { 103 var result = _createTemp(path, (Math.random() * 0x8000000).toInt(), status);
104 if (result != null) {
86 _path = result; 105 _path = result;
87 } else { 106 } else {
88 throw "createTempSync failed"; 107 throw new DirectoryException(
108 "Could not create temporary directory [$_path]: " +
109 "${status._errorMessage}",
110 status._errorCode);
89 } 111 }
90 } 112 }
91 113
92 void deleteSync() { 114 void deleteSync() {
93 if (!_delete(_path)) { 115 if (!_delete(_path)) {
94 throw new DirectoryException("Directory deletion failed: $_path"); 116 throw new DirectoryException("Directory deletion failed: $_path");
95 } 117 }
96 } 118 }
97 119
98 void list([bool recursive = false]) { 120 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"; 214 bool _delete(String path) native "Directory_Delete";
193 215
194 var _dirHandler; 216 var _dirHandler;
195 var _fileHandler; 217 var _fileHandler;
196 var _doneHandler; 218 var _doneHandler;
197 var _createTempHandler; 219 var _createTempHandler;
198 var _errorHandler; 220 var _errorHandler;
199 221
200 String _path; 222 String _path;
201 } 223 }
OLDNEW
« 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