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

Side by Side Diff: lib/src/global_packages.dart

Issue 1239623005: "pub cache repair" prints a more detailed summary. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « lib/src/command/cache_repair.dart ('k') | lib/src/source/cached.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library pub.global_packages; 5 library pub.global_packages;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:path/path.dart' as p; 10 import 'package:path/path.dart' as p;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } else if (id.source == 'path') { 403 } else if (id.source == 'path') {
404 var path = PathSource.pathFromDescription(id.description); 404 var path = PathSource.pathFromDescription(id.description);
405 return '${log.bold(id.name)} ${id.version} at path "$path"'; 405 return '${log.bold(id.name)} ${id.version} at path "$path"';
406 } else { 406 } else {
407 return '${log.bold(id.name)} ${id.version}'; 407 return '${log.bold(id.name)} ${id.version}';
408 } 408 }
409 } 409 }
410 410
411 /// Repairs any corrupted globally-activated packages and their binstubs. 411 /// Repairs any corrupted globally-activated packages and their binstubs.
412 /// 412 ///
413 /// Returns a pair of two [int]s. The first indicates how many packages were 413 /// Returns a pair of two lists of strings. The first indicates which packages
414 /// successfully re-activated; the second indicates how many failed. 414 /// were successfully re-activated; the second indicates which failed.
415 Future<Pair<int, int>> repairActivatedPackages() async { 415 Future<Pair<List<String>, List<String>>> repairActivatedPackages()
416 async {
416 var executables = {}; 417 var executables = {};
417 if (dirExists(_binStubDir)) { 418 if (dirExists(_binStubDir)) {
418 for (var entry in listDir(_binStubDir)) { 419 for (var entry in listDir(_binStubDir)) {
419 try { 420 try {
420 var binstub = readTextFile(entry); 421 var binstub = readTextFile(entry);
421 var package = _binStubProperty(binstub, "Package"); 422 var package = _binStubProperty(binstub, "Package");
422 if (package == null) { 423 if (package == null) {
423 throw new ApplicationException("No 'Package' property."); 424 throw new ApplicationException("No 'Package' property.");
424 } 425 }
425 426
426 var executable = _binStubProperty(binstub, "Executable"); 427 var executable = _binStubProperty(binstub, "Executable");
427 if (executable == null) { 428 if (executable == null) {
428 throw new ApplicationException("No 'Executable' property."); 429 throw new ApplicationException("No 'Executable' property.");
429 } 430 }
430 431
431 executables.putIfAbsent(package, () => []).add(executable); 432 executables.putIfAbsent(package, () => []).add(executable);
432 } catch (error, stackTrace) { 433 } catch (error, stackTrace) {
433 log.error( 434 log.error(
434 "Error reading binstub for " 435 "Error reading binstub for "
435 "\"${p.basenameWithoutExtension(entry)}\"", 436 "\"${p.basenameWithoutExtension(entry)}\"",
436 error, stackTrace); 437 error, stackTrace);
437 438
438 tryDeleteEntry(entry); 439 tryDeleteEntry(entry);
439 } 440 }
440 } 441 }
441 } 442 }
442 443
443 var successes = 0; 444 var successes = [];
444 var failures = 0; 445 var failures = [];
445 if (dirExists(_directory)) { 446 if (dirExists(_directory)) {
446 for (var entry in listDir(_directory)) { 447 for (var entry in listDir(_directory)) {
447 var id; 448 var id;
448 try { 449 try {
449 id = _loadPackageId(entry); 450 id = _loadPackageId(entry);
450 log.message("Reactivating ${log.bold(id.name)} ${id.version}..."); 451 log.message("Reactivating ${log.bold(id.name)} ${id.version}...");
451 452
452 var entrypoint = await find(id.name); 453 var entrypoint = await find(id.name);
453 454
454 var graph = await entrypoint.loadPackageGraph(); 455 var graph = await entrypoint.loadPackageGraph();
455 var snapshots = await _precompileExecutables(entrypoint, id.name); 456 var snapshots = await _precompileExecutables(entrypoint, id.name);
456 var packageExecutables = executables.remove(id.name); 457 var packageExecutables = executables.remove(id.name);
457 if (packageExecutables == null) packageExecutables = []; 458 if (packageExecutables == null) packageExecutables = [];
458 _updateBinStubs(graph.packages[id.name], packageExecutables, 459 _updateBinStubs(graph.packages[id.name], packageExecutables,
459 overwriteBinStubs: true, snapshots: snapshots, 460 overwriteBinStubs: true, snapshots: snapshots,
460 suggestIfNotOnPath: false); 461 suggestIfNotOnPath: false);
461 successes++; 462 successes.add(id.name);
462 } catch (error, stackTrace) { 463 } catch (error, stackTrace) {
463 var message = "Failed to reactivate " 464 var message = "Failed to reactivate "
464 "${log.bold(p.basenameWithoutExtension(entry))}"; 465 "${log.bold(p.basenameWithoutExtension(entry))}";
465 if (id != null) { 466 if (id != null) {
466 message += " ${id.version}"; 467 message += " ${id.version}";
467 if (id.source != "hosted") message += " from ${id.source}"; 468 if (id.source != "hosted") message += " from ${id.source}";
468 } 469 }
469 470
470 log.error(message, error, stackTrace); 471 log.error(message, error, stackTrace);
471 failures++; 472 failures.add(p.basenameWithoutExtension(entry));
472 473
473 tryDeleteEntry(entry); 474 tryDeleteEntry(entry);
474 } 475 }
475 } 476 }
476 } 477 }
477 478
478 if (executables.isNotEmpty) { 479 if (executables.isNotEmpty) {
479 var message = new StringBuffer("Binstubs exist for non-activated " 480 var message = new StringBuffer("Binstubs exist for non-activated "
480 "packages:\n"); 481 "packages:\n");
481 executables.forEach((package, executableNames) { 482 executables.forEach((package, executableNames) {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 } 775 }
775 776
776 /// Returns the value of the property named [name] in the bin stub script 777 /// Returns the value of the property named [name] in the bin stub script
777 /// [source]. 778 /// [source].
778 String _binStubProperty(String source, String name) { 779 String _binStubProperty(String source, String name) {
779 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); 780 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)");
780 var match = pattern.firstMatch(source); 781 var match = pattern.firstMatch(source);
781 return match == null ? null : match[1]; 782 return match == null ? null : match[1];
782 } 783 }
783 } 784 }
OLDNEW
« no previous file with comments | « lib/src/command/cache_repair.dart ('k') | lib/src/source/cached.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698