Index: tlmgr.pl =================================================================== --- tlmgr.pl (revision 10534) +++ tlmgr.pl (working copy) @@ -734,10 +734,45 @@ } } } else { - print "update: $pkg (first remove old, then install new)\n"; - merge_into(\%ret, &remove_package($pkg, $localtlpdb, 1)); + print "update: $pkg (install new ... "; + # we have to be careful hear. If we remove the package and + # later the install_package call which downloads fails, then + # we are in a rather bad shape ... + # + # We will create a list of currently contained files, and a + # list of files in the newer version, and do first install + # the new version, and if that succeeded, we will remove the + # files that are not present anymore in the package + my @oldfiles = $tlp->all_files; + my @newfiles = $mediatlp->all_files; + my %removefiles = (); + # we create an array with key of all the old files, and then + # remove all key/value pairs for files occurring in the new + # files list. The remaining files should be removed. + for my $f (@oldfiles) { + $removefiles{$f} = 1; + } + for my $f (@newfiles) { + delete $removefiles{$f}; + } merge_into(\%ret, $tlmediasrc->install_package($pkg, $localtlpdb, $opt_nodepends, 0)); - print "update: $pkg done\n"; + # If we are still here, then that means that the installation + # has succeeded, because $tlmediasrc->_install_package dies + # in case of download/un-lzma/untar problems + # + print "remove old files ... "; + # we have to chdir to $localtlpdb->root + my $Master = $localtlpdb->root; + chdir ($Master) || die "chdir($Master) failed: $!"; + my @files = keys %removefiles; + my @removals = &removed_dirs (@files); + foreach my $entry (@files) { + unlink $entry; + } + foreach my $entry (@removals) { + rmdir $entry; + } + print "done)\n"; } } } elsif ($rev > $mediarev) {