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

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

Issue 11308298: Restrict the set of files that will be pub lished. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 if (e is! oauth2.ExpirationException) throw e; 108 if (e is! oauth2.ExpirationException) throw e;
109 109
110 printError("Pub's authorization to upload packages has expired and can't " 110 printError("Pub's authorization to upload packages has expired and can't "
111 "be automatically refreshed."); 111 "be automatically refreshed.");
112 return onRun(); 112 return onRun();
113 }); 113 });
114 } 114 }
115 115
116 /// The basenames of files that are automatically excluded from archives.
117 final _BLACKLISTED_FILES = const ['pubspec.lock'];
118
119 /// The basenames of directories that are automatically excluded from
120 /// archives.
121 final _BLACKLISTED_DIRECTORIES = const ['packages'];
122
116 /// Returns a list of files that should be included in the published package. 123 /// Returns a list of files that should be included in the published package.
117 /// If this is a Git repository, this will respect .gitignore; otherwise, it 124 /// If this is a Git repository, this will respect .gitignore; otherwise, it
118 /// will return all non-hidden files. 125 /// will return all non-hidden files.
119 Future<List<String>> get _filesToPublish { 126 Future<List<String>> get _filesToPublish {
120 var rootDir = entrypoint.root.dir; 127 var rootDir = entrypoint.root.dir;
121 return Futures.wait([ 128 return Futures.wait([
122 dirExists(join(rootDir, '.git')), 129 dirExists(join(rootDir, '.git')),
123 git.isInstalled 130 git.isInstalled
124 ]).chain((results) { 131 ]).chain((results) {
125 if (results[0] && results[1]) { 132 if (results[0] && results[1]) {
126 // List all files that aren't gitignored, including those not checked in 133 // List all files that aren't gitignored, including those not checked in
127 // to Git. 134 // to Git.
128 return git.run(["ls-files", "--cached", "--others"]); 135 return git.run(["ls-files", "--cached", "--others"]);
129 } 136 }
130 137
131 return listDir(rootDir, recursive: true).chain((entries) { 138 return listDir(rootDir, recursive: true).chain((entries) {
132 return Futures.wait(entries.map((entry) { 139 return Futures.wait(entries.map((entry) {
133 return fileExists(entry).transform((isFile) => isFile ? entry : null); 140 return fileExists(entry).transform((isFile) => isFile ? entry : null);
134 })); 141 }));
135 }); 142 });
136 }).transform((files) => files.filter((file) { 143 }).transform((files) => files.filter((file) {
137 return file != null && basename(file) != 'packages'; 144 if (file == null || _BLACKLISTED_FILES.contains(basename(file))) {
145 return false;
146 }
147 return !splitPath(file).some(_BLACKLISTED_DIRECTORIES.contains);
138 })); 148 }));
139 } 149 }
140 150
141 /// Parses a response body, assuming it's JSON-formatted. Throws a 151 /// Parses a response body, assuming it's JSON-formatted. Throws a
142 /// user-friendly error if the response body is invalid JSON, or if it's not a 152 /// user-friendly error if the response body is invalid JSON, or if it's not a
143 /// map. 153 /// map.
144 Map _parseJson(http.Response response) { 154 Map _parseJson(http.Response response) {
145 var value; 155 var value;
146 try { 156 try {
147 value = JSON.parse(response.body); 157 value = JSON.parse(response.body);
(...skipping 10 matching lines...) Expand all
158 _expectField(Map map, String key, http.Response response) { 168 _expectField(Map map, String key, http.Response response) {
159 if (map.containsKey(key)) return map[key]; 169 if (map.containsKey(key)) return map[key];
160 _invalidServerResponse(response); 170 _invalidServerResponse(response);
161 } 171 }
162 172
163 /// Throws an error describing an invalid response from the server. 173 /// Throws an error describing an invalid response from the server.
164 void _invalidServerResponse(http.Response response) { 174 void _invalidServerResponse(http.Response response) {
165 throw 'Invalid server response:\n${response.body}'; 175 throw 'Invalid server response:\n${response.body}';
166 } 176 }
167 } 177 }
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