Chromium Code Reviews| 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 implements Directory { | 7 class _Directory implements Directory { |
| 8 static const CREATE_REQUEST = 0; | 8 static const CREATE_REQUEST = 0; |
| 9 static const DELETE_REQUEST = 1; | 9 static const DELETE_REQUEST = 1; |
| 10 static const EXISTS_REQUEST = 2; | 10 static const EXISTS_REQUEST = 2; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 if (_path is !String || newPath is !String) { | 230 if (_path is !String || newPath is !String) { |
| 231 throw new ArgumentError(); | 231 throw new ArgumentError(); |
| 232 } | 232 } |
| 233 var result = _rename(_path, newPath); | 233 var result = _rename(_path, newPath); |
| 234 if (result is OSError) { | 234 if (result is OSError) { |
| 235 throw new DirectoryException("Rename failed", _path, result); | 235 throw new DirectoryException("Rename failed", _path, result); |
| 236 } | 236 } |
| 237 return new Directory(newPath); | 237 return new Directory(newPath); |
| 238 } | 238 } |
| 239 | 239 |
| 240 static String _getListPath(String path) { | |
|
Søren Gjesse
2013/06/17 15:01:55
_removeTrailingPathSeparators?
| |
| 241 while (path.length > 1 && path.endsWith(Platform.pathSeparator)) { | |
| 242 path = path.substring(0, path.length - 1); | |
| 243 } | |
| 244 return path; | |
| 245 } | |
| 246 | |
| 240 Stream<FileSystemEntity> list({bool recursive: false, | 247 Stream<FileSystemEntity> list({bool recursive: false, |
| 241 bool followLinks: true}) { | 248 bool followLinks: true}) { |
| 242 return new _AsyncDirectoryLister(path, recursive, followLinks).stream; | 249 return new _AsyncDirectoryLister(_getListPath(path), |
| 250 recursive, | |
| 251 followLinks).stream; | |
| 243 } | 252 } |
| 244 | 253 |
| 245 List listSync({bool recursive: false, bool followLinks: true}) { | 254 List listSync({bool recursive: false, bool followLinks: true}) { |
| 246 if (_path is! String || recursive is! bool) { | 255 if (recursive is! bool || followLinks is! bool) { |
| 247 throw new ArgumentError(); | 256 throw new ArgumentError(); |
| 248 } | 257 } |
| 249 return _list(_path, recursive, followLinks); | 258 return _list(_getListPath(path), recursive, followLinks); |
| 250 } | 259 } |
| 251 | 260 |
| 252 String get path => _path; | 261 String get path => _path; |
| 253 | 262 |
| 254 String toString() => "Directory: '$path'"; | 263 String toString() => "Directory: '$path'"; |
| 255 | 264 |
| 256 bool _isErrorResponse(response) { | 265 bool _isErrorResponse(response) { |
| 257 return response is List && response[0] != _SUCCESS_RESPONSE; | 266 return response is List && response[0] != _SUCCESS_RESPONSE; |
| 258 } | 267 } |
| 259 | 268 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 controller.addError( | 414 controller.addError( |
| 406 new DirectoryException("Directory listing failed", | 415 new DirectoryException("Directory listing failed", |
| 407 errorPath, | 416 errorPath, |
| 408 err)); | 417 err)); |
| 409 } else { | 418 } else { |
| 410 controller.addError( | 419 controller.addError( |
| 411 new DirectoryException("Internal error")); | 420 new DirectoryException("Internal error")); |
| 412 } | 421 } |
| 413 } | 422 } |
| 414 } | 423 } |
| OLD | NEW |