summaryrefslogtreecommitdiff
path: root/Master/tlpkg/etc/safer-update.diff
blob: 4c600720f14ea4030a364a8b5b51fe2299486d47 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
Index: texmf/scripts/texlive/tlmgr.pl
===================================================================
--- texmf/scripts/texlive/tlmgr.pl	(revision 10534)
+++ texmf/scripts/texlive/tlmgr.pl	(working copy)
@@ -541,15 +541,44 @@
     print "Restoring $pkg, $rev from $opt_backupdir/${pkg}.r${rev}.tar.lzma\n";
     if (!$opt_dry) {
       init_local_db(1);
-      # first remove the package, then reinstall it
-      # this way we get rid of useless files
-      # force the deinstallation since we will reinstall it
+      # get the files of the current package
+      my $tlp = $localtlpdb->get_package($pkg);
+      my @oldfiles;
+      my @newfiles;
+      if (!defined($tlp)) {
+        @oldfiles = ();
+      } else {
+        @oldfiles = $tlp->all_files;
+      }
+      # install the backup package
       $opt_backupdir = abs_path($opt_backupdir);
-      merge_into(\%ret, &remove_package($pkg, $localtlpdb, 1));
       TeXLive::TLMedia->_install_package("$opt_backupdir/${pkg}.r${rev}.tar.lzma" , [] ,$localtlpdb);
       # now we have to read the .tlpobj file and add it to the DB
       my $tlpobj = TeXLive::TLPOBJ->new;
       $tlpobj->from_file($localtlpdb->root . "/tlpkg/tlpobj/$pkg.tlpobj");
+      @newfiles = $tlpobj->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};
+      }
+      # 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;
+      }
+      # add the new tlpobj, overwriting the old one
       $localtlpdb->add_tlpobj($tlpobj);
       $ret = $localtlpdb->get_package($pkg)->make_return_hash_from_executes("enable");
       $localtlpdb->save;
@@ -734,10 +763,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 here. 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) {
@@ -790,6 +854,7 @@
       print "install: $pkg\n";
     } else {
       # install the packages and run postinstall actions (that is the 0)
+      info("install: $pkg\n");
       merge_into(\%ret, $tlmediasrc->install_package($pkg, $localtlpdb, $opt_nodepends, 0));
     }
   }
@@ -943,6 +1008,7 @@
             if ($opt_dry) {
               print "Installing $pkg.$a\n";
             } else {
+              info("install: $pkg.$a\n");
               merge_into(\%ret, $tlmediasrc->install_package("$pkg.$a", $localtlpdb, 0, 0));
             }
           }
@@ -951,8 +1017,11 @@
     }
     if (TeXLive::TLUtils::member('win32', @todoarchs)) {
       # install the necessary win32 stuff
+      info("install: bin-tlperl.win32\n");
       merge_into (\%ret, $tlmediasrc->install_package("bin-tlperl.win32", $localtlpdb, 1, 0));
+      info("install: bin-tlgs.win32\n");
       merge_into (\%ret, $tlmediasrc->install_package("bin-tlgs.win32", $localtlpdb, 1, 0));
+      info("install: bin-tlpsv.win32\n");
       merge_into (\%ret, $tlmediasrc->install_package("bin-tlpsv.win32", $localtlpdb, 1, 0));
     }
     # update the option_archs list of installed archs
Index: tlpkg/TeXLive/TLMedia.pm
===================================================================
--- tlpkg/TeXLive/TLMedia.pm	(revision 10538)
+++ tlpkg/TeXLive/TLMedia.pm	(working copy)
@@ -117,7 +117,6 @@
       # even if opt_doc is false
       $real_opt_doc = 1;
     }
-    info("install: $pkg\n");
     foreach my $h (@::install_packages_hook) {
       &$h("install: $package");
     }