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

Side by Side Diff: utils/pub/command_lish.dart

Issue 11553043: Make listDir always emit paths within the given directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review change + listDir tests Created 8 years 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
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | utils/pub/io.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library command_lish; 5 library command_lish;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:json'; 8 import 'dart:json';
9 import 'dart:uri'; 9 import 'dart:uri';
10 10
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 /// The basenames of directories that are automatically excluded from 130 /// The basenames of directories that are automatically excluded from
131 /// archives. 131 /// archives.
132 final _BLACKLISTED_DIRECTORIES = const ['packages']; 132 final _BLACKLISTED_DIRECTORIES = const ['packages'];
133 133
134 /// Returns a list of files that should be included in the published package. 134 /// Returns a list of files that should be included in the published package.
135 /// If this is a Git repository, this will respect .gitignore; otherwise, it 135 /// If this is a Git repository, this will respect .gitignore; otherwise, it
136 /// will return all non-hidden files. 136 /// will return all non-hidden files.
137 Future<List<String>> get _filesToPublish { 137 Future<List<String>> get _filesToPublish {
138 var rootDir = entrypoint.root.dir; 138 var rootDir = entrypoint.root.dir;
139 139
140 // TODO(rnystrom): listDir() returns real file paths after symlinks are
141 // resolved. This means if libDir contains a symlink, the resulting paths
142 // won't appear to be within it, which confuses relativeTo(). Work around
143 // that here by making sure we have the real path to libDir. Remove this
144 // when #7346 is fixed.
145 rootDir = new File(rootDir).fullPathSync();
146
147 return Futures.wait([ 140 return Futures.wait([
148 dirExists(join(rootDir, '.git')), 141 dirExists(join(rootDir, '.git')),
149 git.isInstalled 142 git.isInstalled
150 ]).chain((results) { 143 ]).chain((results) {
151 if (results[0] && results[1]) { 144 if (results[0] && results[1]) {
152 // List all files that aren't gitignored, including those not checked in 145 // List all files that aren't gitignored, including those not checked in
153 // to Git. 146 // to Git.
154 return git.run(["ls-files", "--cached", "--others"]); 147 return git.run(["ls-files", "--cached", "--others"]);
155 } 148 }
156 149
157 return listDir(rootDir, recursive: true).chain((entries) { 150 return listDir(rootDir, recursive: true).chain((entries) {
158 return Futures.wait(entries.map((entry) { 151 return Futures.wait(entries.map((entry) {
159 return fileExists(entry).transform((isFile) { 152 return fileExists(entry).transform((isFile) {
160 // Skip directories. 153 // Skip directories.
161 if (!isFile) return null; 154 if (!isFile) return null;
162 155
163 // TODO(rnystrom): Making these relative will break archive 156 // TODO(rnystrom): Making these relative will break archive
164 // creation if the cwd is ever *not* the package root directory. 157 // creation if the cwd is ever *not* the package root directory.
165 // Should instead only make these relative right before generating 158 // Should instead only make these relative right before generating
166 // the tree display (which is what really needs them to be). 159 // the tree display (which is what really needs them to be).
167 // Make it relative to the package root. 160 // Make it relative to the package root.
168 entry = relativeTo(entry, rootDir); 161 return relativeTo(entry, rootDir);
169
170 // TODO(rnystrom): dir.list() will include paths with resolved
171 // symlinks. In particular, we'll get paths to symlinked files from
172 // "packages" that reach outside of this package. Since the path
173 // has already been resolved, we don't even see "packages" in that
174 // path anymore.
175 // These should not be included in the archive. As a hack, ignore
176 // any file whose relative path is backing out of the root
177 // directory. Should do something cleaner.
178 var parts = path.split(entry);
179 if (!parts.isEmpty && parts[0] == '..') return null;
180
181 return entry;
182 }); 162 });
183 })); 163 }));
184 }); 164 });
185 }).transform((files) => files.filter((file) { 165 }).transform((files) => files.filter((file) {
186 if (file == null || _BLACKLISTED_FILES.contains(basename(file))) { 166 if (file == null || _BLACKLISTED_FILES.contains(basename(file))) {
187 return false; 167 return false;
188 } 168 }
189 169
190 return !splitPath(file).some(_BLACKLISTED_DIRECTORIES.contains); 170 return !splitPath(file).some(_BLACKLISTED_DIRECTORIES.contains);
191 })); 171 }));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 var s = warnings.length == 1 ? '' : 's'; 217 var s = warnings.length == 1 ? '' : 's';
238 message = "Package has ${warnings.length} warning$s. Upload anyway"; 218 message = "Package has ${warnings.length} warning$s. Upload anyway";
239 } 219 }
240 220
241 return confirm(message).transform((confirmed) { 221 return confirm(message).transform((confirmed) {
242 if (!confirmed) throw "Package upload canceled."; 222 if (!confirmed) throw "Package upload canceled.";
243 }); 223 });
244 }); 224 });
245 } 225 }
246 } 226 }
OLDNEW
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | utils/pub/io.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698