Chromium Code Reviews| Index: sdk/lib/io/directory_impl.dart |
| diff --git a/sdk/lib/io/directory_impl.dart b/sdk/lib/io/directory_impl.dart |
| index f47ef4f90a7a1c5ff441597ba5b783cb9a81383a..55b69149844c632a6af6f4cffc300df140fa47d3 100644 |
| --- a/sdk/lib/io/directory_impl.dart |
| +++ b/sdk/lib/io/directory_impl.dart |
| @@ -237,16 +237,35 @@ class _Directory implements Directory { |
| return new Directory(newPath); |
| } |
| + static String _trimTrailingPathSeparators(String path) { |
| + // Don't handle argument errors here. |
| + if (path is! String) return path; |
| + 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.
|
| + while (path.length > 1 && |
| + (path.endsWith(Platform.pathSeparator) || |
| + path.endsWith('/'))) { |
| + path = path.substring(0, path.length - 1); |
| + } |
| + } else { |
| + while (path.length > 1 && path.endsWith(Platform.pathSeparator)) { |
| + path = path.substring(0, path.length - 1); |
| + } |
| + } |
| + return path; |
| + } |
| + |
| Stream<FileSystemEntity> list({bool recursive: false, |
| bool followLinks: true}) { |
| - return new _AsyncDirectoryLister(path, recursive, followLinks).stream; |
| + return new _AsyncDirectoryLister(_trimTrailingPathSeparators(path), |
| + recursive, |
| + followLinks).stream; |
| } |
| List listSync({bool recursive: false, bool followLinks: true}) { |
| - if (_path is! String || recursive is! bool) { |
| + if (_path is! String || recursive is! bool || followLinks is! bool) { |
| throw new ArgumentError(); |
| } |
| - return _list(_path, recursive, followLinks); |
| + return _list(_trimTrailingPathSeparators(path), recursive, followLinks); |
| } |
| String get path => _path; |