Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: pkg/docgen/lib/src/io.dart

Issue 196133023: pkg/docgen: more cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /// This is a helper library to make working with io easier. 5 /// This is a helper library to make working with io easier.
6 library docgen.io; 6 library docgen.io;
7 7
8 // TODO(janicejl): listDir, canonicalize, resolveLink, and linkExists are from 8 // TODO(janicejl): listDir, canonicalize, resolveLink, and linkExists are from
9 // pub/lib/src/io.dart. If the io.dart file becomes a package, should remove 9 // pub/lib/src/io.dart. If the io.dart file becomes a package, should remove
10 // copy of the functions. 10 // copy of the functions.
11 11
12 import 'dart:collection'; 12 import 'dart:collection';
13 import 'dart:io'; 13 import 'dart:io';
14 import 'package:path/path.dart' as path; 14 import 'package:path/path.dart' as path;
15 15
16 /// Lists the contents of [dir]. If [recursive] is `true`, lists subdirectory 16 /// Lists the contents of [dir].
17 /// contents (defaults to `false`). If [includeHidden] is `true`, includes files 17 ///
18 /// and directories beginning with `.` (defaults to `false`). 18 /// If [recursive] is `true`, lists subdirectory contents (defaults to `false`).
19 ///
20 /// Excludes files and directories beginning with `.`
19 /// 21 ///
20 /// The returned paths are guaranteed to begin with [dir]. 22 /// The returned paths are guaranteed to begin with [dir].
21 List<String> listDir(String dir, {bool recursive: false, 23 List<String> listDir(String dir, {bool recursive: false}) {
22 bool includeHidden: false}) {
23 List<String> doList(String dir, Set<String> listedDirectories) { 24 List<String> doList(String dir, Set<String> listedDirectories) {
24 var contents = <String>[]; 25 var contents = <String>[];
25 26
26 // Avoid recursive symlinks. 27 // Avoid recursive symlinks.
27 var resolvedPath = canonicalize(dir); 28 var resolvedPath = canonicalize(dir);
28 if (listedDirectories.contains(resolvedPath)) return []; 29 if (listedDirectories.contains(resolvedPath)) return [];
29 30
30 listedDirectories = new Set<String>.from(listedDirectories); 31 listedDirectories = new Set<String>.from(listedDirectories);
31 listedDirectories.add(resolvedPath); 32 listedDirectories.add(resolvedPath);
32 33
33 var children = <String>[]; 34 var children = <String>[];
34 for (var entity in new Directory(dir).listSync()) { 35 for (var entity in new Directory(dir).listSync()) {
35 if (!includeHidden && path.basename(entity.path).startsWith('.')) { 36 if (path.basename(entity.path).startsWith('.')) {
36 continue; 37 continue;
37 } 38 }
38 39
39 contents.add(entity.path); 40 contents.add(entity.path);
40 if (entity is Directory) { 41 if (entity is Directory) {
41 // TODO(nweiz): don't manually recurse once issue 4794 is fixed. 42 // TODO(nweiz): don't manually recurse once issue 4794 is fixed.
42 // Note that once we remove the manual recursion, we'll need to 43 // Note that once we remove the manual recursion, we'll need to
43 // explicitly filter out files in hidden directories. 44 // explicitly filter out files in hidden directories.
44 if (recursive) { 45 if (recursive) {
45 children.addAll(doList(entity.path, listedDirectories)); 46 children.addAll(doList(entity.path, listedDirectories));
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 seen.add(link); 148 seen.add(link);
148 link = path.normalize(path.join( 149 link = path.normalize(path.join(
149 path.dirname(link), new Link(link).targetSync())); 150 path.dirname(link), new Link(link).targetSync()));
150 } 151 }
151 return link; 152 return link;
152 } 153 }
153 154
154 /// Returns whether [link] exists on the file system. This will return `true` 155 /// Returns whether [link] exists on the file system. This will return `true`
155 /// for any symlink, regardless of what it points at or whether it's broken. 156 /// for any symlink, regardless of what it points at or whether it's broken.
156 bool linkExists(String link) => new Link(link).existsSync(); 157 bool linkExists(String link) => new Link(link).existsSync();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698