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 _trimTrailingPathSeparators(String path) { | |
| 241 // Don't handle argument errors here. | |
| 242 if (path is! String) return path; | |
| 243 if (Platform.operatingSystem == 'windows') { | |
|
Søren Gjesse
2013/06/18 06:54:09
Won't this loop work for both Windows and non-Wind
Anders Johnsen
2013/06/18 06:55:26
Yeah, but it'll be twice as slow.
| |
| 244 while (path.length > 1 && | |
| 245 (path.endsWith(Platform.pathSeparator) || | |
| 246 path.endsWith('/'))) { | |
| 247 path = path.substring(0, path.length - 1); | |
| 248 } | |
| 249 } else { | |
| 250 while (path.length > 1 && path.endsWith(Platform.pathSeparator)) { | |
| 251 path = path.substring(0, path.length - 1); | |
| 252 } | |
| 253 } | |
| 254 return path; | |
| 255 } | |
| 256 | |
| 240 Stream<FileSystemEntity> list({bool recursive: false, | 257 Stream<FileSystemEntity> list({bool recursive: false, |
| 241 bool followLinks: true}) { | 258 bool followLinks: true}) { |
| 242 return new _AsyncDirectoryLister(path, recursive, followLinks).stream; | 259 return new _AsyncDirectoryLister(_trimTrailingPathSeparators(path), |
| 260 recursive, | |
| 261 followLinks).stream; | |
| 243 } | 262 } |
| 244 | 263 |
| 245 List listSync({bool recursive: false, bool followLinks: true}) { | 264 List listSync({bool recursive: false, bool followLinks: true}) { |
| 246 if (_path is! String || recursive is! bool) { | 265 if (_path is! String || recursive is! bool || followLinks is! bool) { |
| 247 throw new ArgumentError(); | 266 throw new ArgumentError(); |
| 248 } | 267 } |
| 249 return _list(_path, recursive, followLinks); | 268 return _list(_trimTrailingPathSeparators(path), recursive, followLinks); |
| 250 } | 269 } |
| 251 | 270 |
| 252 String get path => _path; | 271 String get path => _path; |
| 253 | 272 |
| 254 String toString() => "Directory: '$path'"; | 273 String toString() => "Directory: '$path'"; |
| 255 | 274 |
| 256 bool _isErrorResponse(response) { | 275 bool _isErrorResponse(response) { |
| 257 return response is List && response[0] != _SUCCESS_RESPONSE; | 276 return response is List && response[0] != _SUCCESS_RESPONSE; |
| 258 } | 277 } |
| 259 | 278 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 controller.addError( | 424 controller.addError( |
| 406 new DirectoryException("Directory listing failed", | 425 new DirectoryException("Directory listing failed", |
| 407 errorPath, | 426 errorPath, |
| 408 err)); | 427 err)); |
| 409 } else { | 428 } else { |
| 410 controller.addError( | 429 controller.addError( |
| 411 new DirectoryException("Internal error")); | 430 new DirectoryException("Internal error")); |
| 412 } | 431 } |
| 413 } | 432 } |
| 414 } | 433 } |
| OLD | NEW |