diff options
author | Norbert Preining <preining@logic.at> | 2017-05-10 04:43:53 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2017-05-10 04:43:53 +0000 |
commit | d83ac58de956453fcb161c2860f8f8cc080a5848 (patch) | |
tree | 75a607ca16dce3e403fd27b59f5bb1a90c8bbea8 /Master/texmf-dist/scripts | |
parent | 9de907501ad193c20b50f301771be176d566f186 (diff) |
factor out backup setup code from action_update
git-svn-id: svn://tug.org/texlive/trunk@44274 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rwxr-xr-x | Master/texmf-dist/scripts/texlive/tlmgr.pl | 92 |
1 files changed, 49 insertions, 43 deletions
diff --git a/Master/texmf-dist/scripts/texlive/tlmgr.pl b/Master/texmf-dist/scripts/texlive/tlmgr.pl index 181a63e5d02..1ac5e16ae8a 100755 --- a/Master/texmf-dist/scripts/texlive/tlmgr.pl +++ b/Master/texmf-dist/scripts/texlive/tlmgr.pl @@ -1783,6 +1783,53 @@ sub restore_one_package { 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 upd_info { } sub action_update { - my $ret = $F_OK; - init_local_db(1); $opts{"no-depends"} = 1 if $opts{"no-depends-at-all"}; @@ -2512,47 +2557,8 @@ sub action_update { } } - 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); - } - } - - # 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; + my ($ret, $autobackup) = setup_backup_directory(); + return ($ret) if ($ret != $F_OK); # these two variables are used throughout this function my $root = $localtlpdb->root; |