Browse files improvements: Save a backup of the old state file, add …

…comments, refactor to limit repeating hardcoded statefile path
  • Loading branch information...
1 parent 3a62063 commit d6ca1c76a5bc255b9f7110de56d30cd32365fafb @japhb japhb committed Aug 16, 2012
Showing with 14 additions and 3 deletions.
  1. +14 −3
@@ -1,16 +1,22 @@
#!/usr/bin/env perl6
use v6;
+# Find old state file
my $home = $*OS eq 'MSWin32' ?? %*ENV<HOMEDRIVE> ~ %*ENV<HOMEPATH> !! %*ENV<HOME>;
+my $state-file = "$home/.panda/state";
-if not "$home/.panda/state".IO.e {
+if not $state-file.IO.e {
say "No need to rebootstrap, running normal bootstrap";
run 'perl6';
-my @modules;
+# Save a copy of the old state file to be written *after* bootstrapping again
+my $old-state = slurp $state-file;
-given open("$home/.panda/state") {
+# Find modules that were installed by request
+# (as opposed to just for dependency resolution)
+my @modules;
+given open($state-file) {
for .lines() -> $line {
my ($name, $state) = split /\s/, $line;
next if $name eq any(<File::Tools JSON::Tiny Test::Mock panda>);
@@ -21,8 +27,13 @@
+# Clean old directories, boostrap a fresh panda,
+# and reinstall all manually-installed modules
# TODO: Make me cross-platform
shell 'rm -rf ~/.perl6/lib';
shell 'rm -rf ~/.panda';
shell 'perl6';
shell "panda install @modules[]";
+# Save the backup state file back to ~/.panda/
+spurt "$state-file.bak", $old-state if $old-state;

0 comments on commit d6ca1c7

Please sign in to comment.