OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Helper functionality to make working with IO easier. | 5 /// Helper functionality to make working with IO easier. |
6 library io; | 6 library io; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 137 |
138 // Avoid recursive symlinks. | 138 // Avoid recursive symlinks. |
139 var resolvedPath = new File(dir).fullPathSync(); | 139 var resolvedPath = new File(dir).fullPathSync(); |
140 if (listedDirectories.contains(resolvedPath)) return []; | 140 if (listedDirectories.contains(resolvedPath)) return []; |
141 | 141 |
142 listedDirectories = new Set<String>.from(listedDirectories); | 142 listedDirectories = new Set<String>.from(listedDirectories); |
143 listedDirectories.add(resolvedPath); | 143 listedDirectories.add(resolvedPath); |
144 | 144 |
145 log.io("Listing directory $dir."); | 145 log.io("Listing directory $dir."); |
146 | 146 |
147 var children = []; | 147 var children = <String>[]; |
148 for (var entity in new Directory(dir).listSync(followLinks: false)) { | 148 for (var entity in new Directory(dir).listSync()) { |
149 var entityPath = entity.path; | 149 if (!includeHidden && path.basename(entity.path).startsWith('.')) { |
150 if (!includeHidden && path.basename(entityPath).startsWith('.')) continue; | 150 continue; |
151 | |
152 // TODO(nweiz): remove this when issue 9832 is fixed. | |
153 if (entity is Link) { | |
154 // We treat broken symlinks as files, in that we don't want to recurse | |
155 // into them. | |
156 entity = dirExists(entityPath) | |
157 ? new Directory(entityPath) | |
158 : new File(entityPath); | |
159 } | 151 } |
160 | 152 |
161 if (entity is File) { | 153 contents.add(entity.path); |
162 contents.add(entityPath); | 154 if (entity is Directory) { |
163 } else if (entity is Directory) { | |
164 contents.add(entityPath); | |
165 // TODO(nweiz): don't manually recurse once issue 4794 is fixed. | 155 // TODO(nweiz): don't manually recurse once issue 4794 is fixed. |
166 // Note that once we remove the manual recursion, we'll need to | 156 // Note that once we remove the manual recursion, we'll need to |
167 // explicitly filter out files in hidden directories. | 157 // explicitly filter out files in hidden directories. |
168 if (recursive) { | 158 if (recursive) { |
169 children.addAll(doList(entityPath, listedDirectories)); | 159 children.addAll(doList(entity.path, listedDirectories)); |
170 } | 160 } |
171 } | 161 } |
172 } | 162 } |
173 | 163 |
174 log.fine("Listed directory $dir:\n${contents.join('\n')}"); | 164 log.fine("Listed directory $dir:\n${contents.join('\n')}"); |
175 contents.addAll(children); | 165 contents.addAll(children); |
176 return contents; | 166 return contents; |
177 } | 167 } |
178 | 168 |
179 return doList(dir, new Set<String>()); | 169 return doList(dir, new Set<String>()); |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 695 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
706 | 696 |
707 bool get success => exitCode == 0; | 697 bool get success => exitCode == 0; |
708 } | 698 } |
709 | 699 |
710 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 700 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
711 Uri _getUri(uri) { | 701 Uri _getUri(uri) { |
712 if (uri is Uri) return uri; | 702 if (uri is Uri) return uri; |
713 return Uri.parse(uri); | 703 return Uri.parse(uri); |
714 } | 704 } |
OLD | NEW |