summaryrefslogtreecommitdiff
path: root/Master/tlpkg/etc/safer-update.diff
blob: 5cb8859aca1687b1b322f59e2a597b08eec12bf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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) {