| 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 class _Directory extends FileSystemEntity implements Directory { | 7 class _Directory extends FileSystemEntity implements Directory { |
| 8 final String path; | 8 final String path; |
| 9 | 9 |
| 10 _Directory(String this.path) { | 10 _Directory(String this.path) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 if (result is OSError) { | 148 if (result is OSError) { |
| 149 throw new DirectoryException("Creation failed", path, result); | 149 throw new DirectoryException("Creation failed", path, result); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 static Directory get systemTemp => new Directory(_systemTemp()); | 153 static Directory get systemTemp => new Directory(_systemTemp()); |
| 154 | 154 |
| 155 Future<Directory> createTemp([String prefix]) { | 155 Future<Directory> createTemp([String prefix]) { |
| 156 if (prefix == null) prefix = ''; | 156 if (prefix == null) prefix = ''; |
| 157 if (path == '') { | 157 if (path == '') { |
| 158 return systemTemp.createTemp(prefix); | 158 throw new ArgumentError( |
| 159 // TODO(13720): On Oct 18, 2013, replace this with | 159 "Directory.createTemp called with an empty path. " |
| 160 // an error. createTemp cannot be called on a Directory with empty path. | 160 "To use the system temp directory, use Directory.systemTemp"); |
| 161 } | 161 } |
| 162 String fullPrefix; | 162 String fullPrefix; |
| 163 if (path.endsWith('/') || (Platform.isWindows && path.endsWith('\\'))) { | 163 if (path.endsWith('/') || (Platform.isWindows && path.endsWith('\\'))) { |
| 164 fullPrefix = "$path$prefix"; | 164 fullPrefix = "$path$prefix"; |
| 165 } else { | 165 } else { |
| 166 fullPrefix = "$path${Platform.pathSeparator}$prefix"; | 166 fullPrefix = "$path${Platform.pathSeparator}$prefix"; |
| 167 } | 167 } |
| 168 return _IOService.dispatch(_DIRECTORY_CREATE_TEMP, [fullPrefix]) | 168 return _IOService.dispatch(_DIRECTORY_CREATE_TEMP, [fullPrefix]) |
| 169 .then((response) { | 169 .then((response) { |
| 170 if (_isErrorResponse(response)) { | 170 if (_isErrorResponse(response)) { |
| 171 throw _exceptionOrErrorFromResponse( | 171 throw _exceptionOrErrorFromResponse( |
| 172 response, "Creation of temporary directory failed"); | 172 response, "Creation of temporary directory failed"); |
| 173 } | 173 } |
| 174 return new Directory(response); | 174 return new Directory(response); |
| 175 }); | 175 }); |
| 176 } | 176 } |
| 177 | 177 |
| 178 Directory createTempSync([String prefix]) { | 178 Directory createTempSync([String prefix]) { |
| 179 if (prefix == null) prefix = ''; | 179 if (prefix == null) prefix = ''; |
| 180 if (path == '') { | 180 if (path == '') { |
| 181 return systemTemp.createTempSync(prefix); | 181 throw new ArgumentError( |
| 182 // TODO(13720): On Oct 18, 2013, replace this with | 182 "Directory.createTemp called with an empty path. " |
| 183 // an error. createTemp cannot be called on a Directory with empty path. | 183 "To use the system temp directory, use Directory.systemTemp"); |
| 184 } | 184 } |
| 185 String fullPrefix; | 185 String fullPrefix; |
| 186 if (path.endsWith('/') || (Platform.isWindows && path.endsWith('\\'))) { | 186 if (path.endsWith('/') || (Platform.isWindows && path.endsWith('\\'))) { |
| 187 fullPrefix = "$path$prefix"; | 187 fullPrefix = "$path$prefix"; |
| 188 } else { | 188 } else { |
| 189 fullPrefix = "$path${Platform.pathSeparator}$prefix"; | 189 fullPrefix = "$path${Platform.pathSeparator}$prefix"; |
| 190 } | 190 } |
| 191 var result = _createTemp(fullPrefix); | 191 var result = _createTemp(fullPrefix); |
| 192 if (result is OSError) { | 192 if (result is OSError) { |
| 193 throw new DirectoryException("Creation of temporary directory failed", | 193 throw new DirectoryException("Creation of temporary directory failed", |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 controller.addError( | 396 controller.addError( |
| 397 new DirectoryException("Directory listing failed", | 397 new DirectoryException("Directory listing failed", |
| 398 errorPath, | 398 errorPath, |
| 399 err)); | 399 err)); |
| 400 } else { | 400 } else { |
| 401 controller.addError( | 401 controller.addError( |
| 402 new DirectoryException("Internal error")); | 402 new DirectoryException("Internal error")); |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 } | 405 } |
| OLD | NEW |