OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | |
13 class _Directory implements Directory { | 6 class _Directory implements Directory { |
14 static final kCreateRequest = 0; | 7 static final kCreateRequest = 0; |
15 static final kDeleteRequest = 1; | 8 static final kDeleteRequest = 1; |
16 static final kExistsRequest = 2; | 9 static final kExistsRequest = 2; |
17 static final kCreateTempRequest = 3; | 10 static final kCreateTempRequest = 3; |
18 static final kListRequest = 4; | 11 static final kListRequest = 4; |
19 | 12 |
20 _Directory(String this._path); | 13 _Directory(String this._path); |
21 _Directory.current() : _path = _current(); | 14 _Directory.current() : _path = _current(); |
22 | 15 |
23 static String _current() native "Directory_Current"; | 16 static String _current() native "Directory_Current"; |
24 static String _createTemp(String template, | 17 static String _createTemp(String template, |
25 _OSStatus status) native "Directory_CreateTemp"; | 18 OSError osError) native "Directory_CreateTemp"; |
26 static int _exists(String path) native "Directory_Exists"; | 19 static int _exists(String path) native "Directory_Exists"; |
27 static bool _create(String path) native "Directory_Create"; | 20 static bool _create(String path) native "Directory_Create"; |
28 static bool _delete(String path, bool recursive) native "Directory_Delete"; | 21 static bool _delete(String path, bool recursive) native "Directory_Delete"; |
29 static SendPort _newServicePort() native "Directory_NewServicePort"; | 22 static SendPort _newServicePort() native "Directory_NewServicePort"; |
30 | 23 |
31 void exists(void callback(bool exists)) { | 24 void exists(void callback(bool exists)) { |
32 _ensureDirectoryService(); | 25 _ensureDirectoryService(); |
33 List request = new List(2); | 26 List request = new List(2); |
34 request[0] = kExistsRequest; | 27 request[0] = kExistsRequest; |
35 request[1] = _path; | 28 request[1] = _path; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 _path = result; | 75 _path = result; |
83 callback(); | 76 callback(); |
84 } else if (_onError != null) { | 77 } else if (_onError != null) { |
85 _onError("Could not create temporary directory [$_path]: " + | 78 _onError("Could not create temporary directory [$_path]: " + |
86 "${result[1]}"); | 79 "${result[1]}"); |
87 } | 80 } |
88 }); | 81 }); |
89 } | 82 } |
90 | 83 |
91 void createTempSync() { | 84 void createTempSync() { |
92 var status = new _OSStatus(); | 85 var osError = new OSError(); |
93 var result = _createTemp(path, status); | 86 var result = _createTemp(path, osError); |
94 if (result != null) { | 87 if (result != null) { |
95 _path = result; | 88 _path = result; |
96 } else { | 89 } else { |
97 throw new DirectoryException( | 90 throw new DirectoryException( |
98 "Could not create temporary directory [$_path]: " + | 91 "Could not create temporary directory [$_path]: " + |
99 "${status._errorMessage}", | 92 "${status._errorMessage}", |
100 status._errorCode); | 93 status._errorCode); |
101 } | 94 } |
102 } | 95 } |
103 | 96 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 195 } |
203 | 196 |
204 var _onDir; | 197 var _onDir; |
205 var _onFile; | 198 var _onFile; |
206 var _onDone; | 199 var _onDone; |
207 var _onError; | 200 var _onError; |
208 | 201 |
209 String _path; | 202 String _path; |
210 SendPort _directoryService; | 203 SendPort _directoryService; |
211 } | 204 } |
OLD | NEW |