texlive[44275] Master/texmf-dist/scripts/texlive/tlmgr.pl: backup

commits+preining at tug.org commits+preining at tug.org
Wed May 10 06:44:03 CEST 2017


Revision: 44275
          http://tug.org/svn/texlive?view=revision&revision=44275
Author:   preining
Date:     2017-05-10 06:44:02 +0200 (Wed, 10 May 2017)
Log Message:
-----------
backup pkgs in action_remove, allow for --backup etc in remove

Modified Paths:
--------------
    trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl

Modified: trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
===================================================================
--- trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2017-05-10 04:43:53 UTC (rev 44274)
+++ trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2017-05-10 04:44:02 UTC (rev 44275)
@@ -274,6 +274,8 @@
   },
   "remove" => { 
     "options"  => {
+      "backup" => 1,
+      "backupdir" => "=s",
       "dry-run|n" => 1,
       "force" => 1,
       "no-depends"        => 1,
@@ -1011,8 +1013,28 @@
 #   will absolutely only install foo bar baz not even taking .ARCH into
 #   account
 #
+
+sub backup_and_remove_package {
+  my ($pkg, $autobackup) = @_;
+  my $tlp = $localtlpdb->get_package($pkg);
+  if (!defined($tlp)) {
+    info("$pkg: package not present, cannot remove\n");
+    return($F_WARNING);
+  }
+  if ($opts{"backup"}) {
+    $tlp->make_container("xz", $localtlpdb->root,
+                         $opts{"backupdir"}, 
+                         "${pkg}.r" . $tlp->revision,
+                         $tlp->relocated);
+    if ($autobackup) {
+      # in case we do auto backups we remove older backups
+      clear_old_backups($pkg, $opts{"backupdir"}, $autobackup);
+    }
+  }
+  return($localtlpdb->remove_package($pkg));
+}
+
 sub action_remove {
-  my $ret = $F_OK;
   # we do the following:
   # - (not implemented) order collections such that those depending on
   #   other collections are first removed, and then those which only
@@ -1034,6 +1056,10 @@
   init_local_db();
   return($F_ERROR) if !check_on_writable();
   info("$prg remove: dry run, no changes will be made\n") if $opts{"dry-run"};
+
+  my ($ret, $autobackup) = setup_backup_directory();
+  return ($ret) if ($ret != $F_OK);
+
   my @packs = @ARGV;
   #
   # we have to be careful not to remove too many packages. The idea is
@@ -1099,7 +1125,7 @@
         my $foo = 0;
         info ("$prg: removing $pkg\n");
         if (!$opts{"dry-run"}) {
-          $foo = $localtlpdb->remove_package($pkg);
+          $foo = backup_and_remove_package($pkg, $autobackup);
           logpackage("remove: $pkg");
         }
         if ($foo) {
@@ -1120,7 +1146,7 @@
     if (!defined($already_removed{$pkg})) {
       info ("$prg: removing package $pkg\n");
       if (!$opts{"dry-run"}) {
-        if ($localtlpdb->remove_package($pkg)) {
+        if (backup_and_remove_package($pkg, $autobackup)) {
           # removal was successful
           logpackage("remove: $pkg");
           $already_removed{$pkg} = 1;
@@ -2926,17 +2952,8 @@
             debug("$prg: warn, relocated bit set for $p, but that is wrong!\n");
             $pkg->relocated(0);
           }
-          if ($opts{"backup"}) {
-            $pkg->make_container("xz", $root,
-                                 $opts{"backupdir"}, 
-                                 "${p}.r" . $pkg->revision,
-                                 $pkg->relocated);
-            if ($autobackup) {
-              # in case we do auto backups we remove older backups
-              clear_old_backups($p, $opts{"backupdir"}, $autobackup);
-            }
-          }
-          $localtlpdb->remove_package($p);
+          # TODO we do not check return value here!
+          backup_and_remove_package($p, $autobackup);
           logpackage("remove: $p");
         }
         info("done\n") unless $::machinereadable;
@@ -7733,6 +7750,23 @@
 
 =over 4
 
+=item B<--backup> and B<--backupdir> I<directory>
+
+These two options control the creation of backups of packages I<before>
+removal; that is, backup of packages as currently installed.  If
+neither of these options are given, no backup package will be saved. If
+C<--backupdir> is given and specifies a writable directory then a backup
+will be made in that location. If only C<--backup> is given, then a
+backup will be made to the directory previously set via the C<option>
+action (see below). If both are given then a backup will be made to the
+specified I<directory>.
+
+You can set options via the C<option> action to automatically create
+backups for all packages, and/or keep only a certain number of
+backups.  Please see the C<option> action for details.
+
+The C<restore> action explains how to restore from a backup.
+
 =item B<--no-depends>
 
 Do not remove dependent packages.



More information about the tex-live-commits mailing list