texlive[44274] Master/texmf-dist/scripts/texlive/tlmgr.pl: factor out

commits+preining at tug.org commits+preining at tug.org
Wed May 10 06:43:54 CEST 2017


Revision: 44274
          http://tug.org/svn/texlive?view=revision&revision=44274
Author:   preining
Date:     2017-05-10 06:43:53 +0200 (Wed, 10 May 2017)
Log Message:
-----------
factor out backup setup code from action_update

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 02:55:07 UTC (rev 44273)
+++ trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl	2017-05-10 04:43:53 UTC (rev 44274)
@@ -1783,6 +1783,53 @@
   return ($F_OK);
 }
 
+sub setup_backup_directory {
+  my $ret = $F_OK;
+  my $autobackup = 0;
+  # check for the tlpdb option autobackup, and if present and true (!= 0)
+  # assume we are doing backups
+  if (!$opts{"backup"}) {
+    $autobackup = $localtlpdb->option("autobackup");
+    if ($autobackup) {
+      # check the format, we currently allow only natural numbers, and -1
+      if ($autobackup eq "-1") {
+        debug ("Automatic backups activated, keeping all backups.\n");
+        $opts{"backup"} = 1;
+      } elsif ($autobackup eq "0") {
+        debug ("Automatic backups disabled.\n");
+      } elsif ($autobackup =~ m/^[0-9]+$/) {
+        debug ("Automatic backups activated, keeping $autobackup backups.\n");
+        $opts{"backup"} = 1;
+      } else {
+        tlwarn ("$prg: Option autobackup can only be an integer >= -1.\n");
+        tlwarn ("$prg: Disabling auto backups.\n");
+        $localtlpdb->option("autobackup", 0);
+        $autobackup = 0;
+        $ret |= $F_WARNING;
+      }
+    }
+  }
+
+  # cmd line --backup, we check for --backupdir, and if that is not given
+  # we try to get the default from the tlpdb. If that doesn't work, exit.
+  if ($opts{"backup"}) {
+    my ($a, $b) = check_backupdir_selection();
+    if ($a & $F_ERROR) {
+      # in all these cases we want to terminate in the non-gui mode
+      tlwarn($b);
+      return ($F_ERROR, $autobackup);
+    }
+  }
+
+  # finally, if we have --backupdir, but no --backup, just enable it
+  $opts{"backup"} = 1 if $opts{"backupdir"};
+
+  info("$prg: saving backups to $opts{'backupdir'}\n")
+    if $opts{"backup"} && !$::machinereadable;
+  
+  return ($ret, $autobackup);
+}
+
 sub check_backupdir_selection {
   my $warntext = "";
   if ($opts{"backupdir"}) {
@@ -2466,8 +2513,6 @@
 }
 
 sub action_update {
-  my $ret = $F_OK;
-
   init_local_db(1);
   $opts{"no-depends"} = 1 if $opts{"no-depends-at-all"};
 
@@ -2512,48 +2557,9 @@
     }
   }
 
-  my $autobackup = 0;
-  # check for the tlpdb option autobackup, and if present and true (!= 0)
-  # assume we are doing backups
-  if (!$opts{"backup"}) {
-    $autobackup = $localtlpdb->option("autobackup");
-    if ($autobackup) {
-      # check the format, we currently allow only natural numbers, and -1
-      if ($autobackup eq "-1") {
-        debug ("Automatic backups activated, keeping all backups.\n");
-        $opts{"backup"} = 1;
-      } elsif ($autobackup eq "0") {
-        debug ("Automatic backups disabled.\n");
-      } elsif ($autobackup =~ m/^[0-9]+$/) {
-        debug ("Automatic backups activated, keeping $autobackup backups.\n");
-        $opts{"backup"} = 1;
-      } else {
-        tlwarn ("$prg: Option autobackup can only be an integer >= -1.\n");
-        tlwarn ("$prg: Disabling auto backups.\n");
-        $localtlpdb->option("autobackup", 0);
-        $autobackup = 0;
-        $ret |= $F_WARNING;
-      }
-    }
-  }
+  my ($ret, $autobackup) = setup_backup_directory();
+  return ($ret) if ($ret != $F_OK);
 
-  # cmd line --backup, we check for --backupdir, and if that is not given
-  # we try to get the default from the tlpdb. If that doesn't work, exit.
-  if ($opts{"backup"}) {
-    my ($a, $b) = check_backupdir_selection();
-    if ($a & $F_ERROR) {
-      # in all these cases we want to terminate in the non-gui mode
-      tlwarn($b);
-      return ($F_ERROR);
-    }
-  }
-
-  # finally, if we have --backupdir, but no --backup, just enable it
-  $opts{"backup"} = 1 if $opts{"backupdir"};
-
-  info("$prg: saving backups to $opts{'backupdir'}\n")
-    if $opts{"backup"} && !$::machinereadable;
-
   # these two variables are used throughout this function
   my $root = $localtlpdb->root;
   my $temp = TeXLive::TLUtils::tl_tmpdir();



More information about the tex-live-commits mailing list