diff options
author | Norbert Preining <preining@logic.at> | 2008-12-19 14:31:43 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2008-12-19 14:31:43 +0000 |
commit | 0840ed675e3d9966b766fa6d713d62f6b62fffc9 (patch) | |
tree | e11fd07148c0fdbf487f6c1cc97bdacf3e437370 | |
parent | 9eb50e44760ff0be93d73c751e35890ccb3865f7 (diff) |
rewort tlmgr2 action_update program flow:
- first collect the list of packages to be updated or installed
- then do only the install
- then do only the update
(maybe that should be reversed??? so that files can be moved *between*
packages)
This allows a cleaner code, the sub is already tooooo long, and a bit of
structuring there does not hurt.
git-svn-id: svn://tug.org/texlive/trunk@11654 c570f23f-e606-0410-a88d-b1316a301751
-rwxr-xr-x | Master/texmf/scripts/texlive/tlmgr2.pl | 261 |
1 files changed, 150 insertions, 111 deletions
diff --git a/Master/texmf/scripts/texlive/tlmgr2.pl b/Master/texmf/scripts/texlive/tlmgr2.pl index fd99e353720..577759fd161 100755 --- a/Master/texmf/scripts/texlive/tlmgr2.pl +++ b/Master/texmf/scripts/texlive/tlmgr2.pl @@ -1445,6 +1445,10 @@ sub action_update { } else { @todo = @ARGV; } + # don't do anything if we have been invoced in a strange way + if (!@todo) { + tlwarn("tlmgr update: please specify a list of packages or --all.\n"); + } # # we have to remove all the stuff before we install other packages @@ -1467,10 +1471,6 @@ sub action_update { } } - if (!@todo) { - tlwarn("tlmgr update: please specify a list of packages or --all.\n"); - } - # update all .ARCH dependencies, too, unless $opts{"no-depends-at-all"}: @todo = $mediatlpdb->expand_dependencies("-only-arch", $localtlpdb, @todo) unless $opts{"no-depends-at-all"}; @@ -1479,6 +1479,11 @@ sub action_update { @todo = $mediatlpdb->expand_dependencies("-no-collections",$localtlpdb,@todo) unless $opts{"no-depends"}; + # + # we first collect the list of packages to be actually updated or installed + my %updated; + my %new; + foreach my $pkg (sort @todo) { next if ($pkg =~ m/^00texlive/); my $tlp = $localtlpdb->get_package($pkg); @@ -1505,6 +1510,7 @@ sub action_update { # do nothing here, it will be reported below. } elsif (defined($removals{$pkg})) { # skipping this package, it has been removed due to server removal + # and has already been removed next; } else { tlwarn("\ntlmgr: $pkg mentioned, neither new nor forcibly removed\n"); @@ -1517,24 +1523,66 @@ sub action_update { next; } my $mediarev = $mediatlp->revision; + $new{$pkg} = 1; + next; + } + my $rev = $tlp->revision; + my $mediatlp = $mediatlpdb->get_package($pkg); + if (!defined($mediatlp)) { + debug("$pkg cannot be found in $location\n"); + next; + } + my $mediarev = $mediatlp->revision; + if ($rev < $mediarev) { + $updated{$pkg} = 1; + # machine_line($pkg, $FLAG_UPDATE, $rev, $mediarev); + } elsif ($rev > $mediarev) { if ($::machinereadable) { - machine_line($pkg, $FLAG_AUTOINSTALL, "-", $mediatlp->revision); - } else { - info("auto-install: $pkg\n"); - } - next if ($opts{"dry-run"} || $opts{"list"}); - my $foo = $tlmediasrc->install_package($pkg, $localtlpdb); - if (ref $foo) { - # installation succeeded because we got a reference - merge_into (\%ret, $foo); - logpackage("auto-install new: $pkg ($mediarev)"); - $nrupdated++; + machine_line($pkg, $FLAG_REVERSED_UPDATE, $rev, $mediarev); } else { - tlwarn("$0: couldn't install new package $pkg\n"); + info("$pkg: local revision ($rev) is newer than revision in $location" + . " ($mediarev), not updating.\n"); } + } + } + for my $i (keys %new) { + debug("$i new package\n"); + } + for my $i (keys %updated) { + debug("$i upd package\n"); + } + + # install all the new packages first + for my $pkg (sort keys %new) { + # install new packages + my $mediatlp = $mediatlpdb->get_package($pkg); + if (!defined($mediatlp)) { + tlwarn("\nShould not happen: $pkg not found in $location\n"); next; } + my $mediarev = $mediatlp->revision; + if ($::machinereadable) { + machine_line($pkg, $FLAG_AUTOINSTALL, "-", $mediatlp->revision); + } else { + info("auto-install: $pkg\n"); + } + next if ($opts{"dry-run"} || $opts{"list"}); + my $foo = $tlmediasrc->install_package($pkg, $localtlpdb); + if (ref $foo) { + # installation succeeded because we got a reference + merge_into (\%ret, $foo); + logpackage("auto-install new: $pkg ($mediarev)"); + $nrupdated++; + } else { + tlwarn("$0: couldn't install new package $pkg\n"); + } + } + # + foreach my $pkg (sort keys %updated) { + next if ($pkg =~ m/^00texlive/); + my $tlp = $localtlpdb->get_package($pkg); + # we checked already that this package is present! my $unwind_package; my $remove_unwind_container = 0; my $rev = $tlp->revision; @@ -1544,115 +1592,106 @@ sub action_update { next; } my $mediarev = $mediatlp->revision; - if ($rev < $mediarev) { - $nrupdated++; - if ($opts{"list"}) { - if ($::machinereadable) { - machine_line($pkg, $FLAG_UPDATE, $rev, $mediarev); - } else { - info("$pkg: local: $rev, source: $mediarev\n"); - } + $nrupdated++; + if ($opts{"list"}) { + if ($::machinereadable) { + machine_line($pkg, $FLAG_UPDATE, $rev, $mediarev); } else { - if ($opts{"backup"} && !$opts{"dry-run"}) { - $tlp->make_container("lzma", $root, - $opts{"backupdir"}, "${pkg}.r" . $tlp->revision); - $unwind_package = - "$opts{'backupdir'}/${pkg}.r" . $tlp->revision . ".tar.lzma"; - - if ($autobackup) { - # in case we do auto backups we remove older backups - clear_old_backups($pkg, $opts{"backupdir"}, $autobackup); - } + info("$pkg: local: $rev, source: $mediarev\n"); + } + } else { + if ($opts{"backup"} && !$opts{"dry-run"}) { + $tlp->make_container("lzma", $root, + $opts{"backupdir"}, "${pkg}.r" . $tlp->revision); + $unwind_package = + "$opts{'backupdir'}/${pkg}.r" . $tlp->revision . ".tar.lzma"; + + if ($autobackup) { + # in case we do auto backups we remove older backups + clear_old_backups($pkg, $opts{"backupdir"}, $autobackup); } + } - if (win32() && ($pkg =~ m/$WinSpecialUpdatePackagesRegexp/)) { - add_w32_updater($mediatlp, $opts{"dry-run"}); + if (win32() && ($pkg =~ m/$WinSpecialUpdatePackagesRegexp/)) { + add_w32_updater($mediatlp, $opts{"dry-run"}); + } else { + info("update: $pkg ($rev -> $mediarev)"); + if ($opts{"dry-run"}) { + info("\n"); + next; } else { - info("update: $pkg ($rev -> $mediarev)"); - if ($opts{"dry-run"}) { - info("\n"); + info(" ... "); # more to come + } + + if (!$unwind_package) { + # no backup was made, so let us create a temporary .tar file + # of the package + my $tlp = $localtlpdb->get_package($pkg); + my ($s, $m, $fullname) = $tlp->make_container("tar", $root, $temp, + "__BACKUP_${pkg}.r" . $tlp->revision); + if ($s <= 0) { + tlwarn("\n$0: Creation of backup container of $pkg failed.\n"); + tlwarn("Continuing to update other packages, please retry...\n"); + # we should try to update other packages at least next; - } else { - info(" ... "); # more to come } - - if (!$unwind_package) { - # no backup was made, so let us create a temporary .tar file - # of the package - my $tlp = $localtlpdb->get_package($pkg); - my ($s, $m, $fullname) = $tlp->make_container("tar", $root, $temp, - "__BACKUP_${pkg}.r" . $tlp->revision); - if ($s <= 0) { - tlwarn("\n$0: Creation of backup container of $pkg failed.\n"); - tlwarn("Continuing to update other packages, please retry...\n"); - # we should try to update other packages at least - next; - } + $remove_unwind_container = 1; + $unwind_package = "$fullname"; + } + # first remove the package, then reinstall it + # this way we get rid of useless files + # force the deinstallation since we will reinstall it + # + # the remove_package should also remove empty dirs in case + # a dir is changed into a file + merge_into(\%ret, &remove_package($pkg, $localtlpdb)); + my $foo = $tlmediasrc->install_package($pkg, $localtlpdb); + if (ref $foo) { + # installation succeeded because we got a reference + merge_into (\%ret, $foo); + logpackage("update: $pkg ($rev -> $mediarev)"); + unlink($unwind_package) if $remove_unwind_container; + } else { + # install_package returned a scalar, so error. + # now in fact we should do some cleanup, removing files and + # dirs from the new package before re-installing the old one. + # TODO + logpackage("failed update: $pkg ($rev -> $mediarev)"); + tlwarn("\n\nInstallation of new version of $pkg did fail, trying to unwind.\n"); + if (win32()) { + # w32 is notorious for not releasing a file immediately + # we experienced permission denied errors + my $newname = $unwind_package; + $newname =~ s/__BACKUP/___BACKUP/; + copy ("-f", $unwind_package, $newname); + # try to remove the file if has been created by us + unlink($unwind_package) if $remove_unwind_container; + # and make sure that the temporary file is removed in any case $remove_unwind_container = 1; - $unwind_package = "$fullname"; + $unwind_package = $newname; } - # first remove the package, then reinstall it - # this way we get rid of useless files - # force the deinstallation since we will reinstall it - # - # the remove_package should also remove empty dirs in case - # a dir is changed into a file - merge_into(\%ret, &remove_package($pkg, $localtlpdb)); - my $foo = $tlmediasrc->install_package($pkg, $localtlpdb); - if (ref $foo) { - # installation succeeded because we got a reference - merge_into (\%ret, $foo); - logpackage("update: $pkg ($rev -> $mediarev)"); - unlink($unwind_package) if $remove_unwind_container; + my $instret = TeXLive::TLMedia->_install_package("$unwind_package", + [], $localtlpdb); + if ($instret) { + # now we have to include the tlpobj + my $tlpobj = TeXLive::TLPOBJ->new; + $tlpobj->from_file($root . "/tlpkg/tlpobj/$pkg.tlpobj"); + $localtlpdb->add_tlpobj($tlpobj); + $localtlpdb->save; + logpackage("restore: $pkg ($rev)"); + tlwarn("Restoring old package state succeeded.\n"); } else { - # install_package returned a scalar, so error. - # now in fact we should do some cleanup, removing files and - # dirs from the new package before re-installing the old one. - # TODO - logpackage("failed update: $pkg ($rev -> $mediarev)"); - tlwarn("\n\nInstallation of new version of $pkg did fail, trying to unwind.\n"); - if (win32()) { - # w32 is notorious for not releasing a file immediately - # we experienced permission denied errors - my $newname = $unwind_package; - $newname =~ s/__BACKUP/___BACKUP/; - copy ("-f", $unwind_package, $newname); - # try to remove the file if has been created by us - unlink($unwind_package) if $remove_unwind_container; - # and make sure that the temporary file is removed in any case - $remove_unwind_container = 1; - $unwind_package = $newname; - } - my $instret = TeXLive::TLMedia->_install_package("$unwind_package", - [], $localtlpdb); - if ($instret) { - # now we have to include the tlpobj - my $tlpobj = TeXLive::TLPOBJ->new; - $tlpobj->from_file($root . "/tlpkg/tlpobj/$pkg.tlpobj"); - $localtlpdb->add_tlpobj($tlpobj); - $localtlpdb->save; - logpackage("restore: $pkg ($rev)"); - tlwarn("Restoring old package state succeeded.\n"); - } else { - logpackage("restore failed: $pkg ($rev)"); - tlwarn("Restoring of old package did NOT succeed.\n"); - tlwarn("Most likely repair: run tlmgr install $pkg and hope.\n"); - } - unlink($unwind_package) if $remove_unwind_container; + logpackage("restore failed: $pkg ($rev)"); + tlwarn("Restoring of old package did NOT succeed.\n"); + tlwarn("Most likely repair: run tlmgr install $pkg and hope.\n"); } - info("done\n"); + unlink($unwind_package) if $remove_unwind_container; } + info("done\n"); } - } elsif ($rev > $mediarev) { - if ($::machinereadable) { - machine_line($pkg, $FLAG_REVERSED_UPDATE, $rev, $mediarev); - } else { - info("$pkg: local revision ($rev) is newer than revision in $location" - . " ($mediarev), not updating.\n"); - } - next; } } + # that already checks whether we actually have to do something close_w32_updater(); if (($nrupdated == 0) && ($tlmediasrc->media ne "NET") && $opts{"all"}) { |