summaryrefslogtreecommitdiff
path: root/Master/tlpkg/etc/safer-update.diff
blob: c93fdc64b7222a3526bd63ba77ef0f56e2a01906 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
Index: texmf/scripts/texlive/tlmgr.pl
===================================================================
--- texmf/scripts/texlive/tlmgr.pl	(revision 10623)
+++ texmf/scripts/texlive/tlmgr.pl	(working copy)
@@ -550,15 +550,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;
@@ -664,6 +693,7 @@
       printf STDERR "$0: cannot find package $pkg\n";
       next;
     }
+    my $unwind_package;
     my $rev = $tlp->revision;
     my $mediatlp = $mediatlpdb->get_package($pkg);
     if (!defined($mediatlp)) {
@@ -689,6 +719,7 @@
             my $tlp = $localtlpdb->get_package($pkg);
             $tlp->make_container("lzma", $localtlpdb->root, 
                                  $opt_backupdir, "${pkg}.r" . $tlp->revision);
+            $unwind_package = "$opt_backupdir/${pkg}.r" . $tlp->revision " . ".tar.lzma";
           }
         }
         if (win32() && ($pkg =~ m/$WinSpecialUpdatePackagesRegexp/)) {
@@ -744,10 +775,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) {
@@ -800,6 +866,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));
     }
   }
@@ -963,6 +1030,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));
             }
           }
@@ -971,8 +1039,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/TLPOBJ.pm
===================================================================
--- tlpkg/TeXLive/TLPOBJ.pm	(revision 10611)
+++ tlpkg/TeXLive/TLPOBJ.pm	(working copy)
@@ -512,8 +512,8 @@
 
 sub make_container {
   my ($self,$type,$instroot,$destdir,$containername,$relative) = @_;
-  if ($type ne "lzma") {
-    die("TLPOBJ currently supports only lzma containers");
+  if (($type ne "lzma") && ($type ne "tar")) {
+    die("TLPOBJ currently supports only plain or lzma containers");
   }
   if (!defined($containername)) {
     $containername = $self->name;
@@ -572,18 +572,25 @@
   close(TMP);
   push @files, "$tlpobjdir/$self->{'name'}.tlpobj";
   $tarname = "$containername.tar";
-  $containername = "$tarname.lzma";
+  if ($type eq "tar") {
+    $containername = $tarname;
+  } else {
+    $containername = "$tarname.lzma";
+  }
 
   # start the whole fun
   my $tar = $::progs{'tar'};
-  my $lzma = $::progs{'lzma'};
+  my $lzma;
   if (!defined($tar)) {
     tlwarn("Programs have not been set up, trying with \"tar\"!\n");
     $tar = "tar";
   }
-  if (!defined($lzma)) {
-    tlwarn("Programs have not been set up, trying with \"lzma\"!\n");
-    $lzma = "lzma";
+  if ($type eq "lzma") {
+    my $lzma = $::progs{'lzma'};
+    if (!defined($lzma)) {
+      tlwarn("Programs have not been set up, trying with \"lzma\"!\n");
+      $lzma = "lzma";
+    }
   }
   my @cmdline = ($tar, "--owner", "0", "--group", "0", "-c", "-f", "$destdir/$tarname", "--files-from=-");
   unlink("$destdir/$containername");
@@ -603,14 +610,16 @@
     }
   } @files;
   close ZIP;
-  if (-r "$destdir/$tarname") {
-    system($lzma, "--force", "-z", "$destdir/$tarname");
-  } else {
-    tlwarn("Couldn't find $destdir/$tarname\n");
+  if ($type eq "lzma") {
+    if (-r "$destdir/$tarname") {
+      system($lzma, "--force", "-z", "$destdir/$tarname");
+    } else {
+      tlwarn("Couldn't find $destdir/$tarname\n");
+    }
   }
   # compute the size
-  my $size = (stat "$destdir/$tarname.lzma") [7];
-  my $m = TeXLive::TLUtils::tlmd5("$destdir/$tarname.lzma");
+  my $size = (stat "$destdir/$containername") [7];
+  my $m = TeXLive::TLUtils::tlmd5("$destdir/$containername");
   # cleaning up
   unlink("$tlpobjdir/$self->{'name'}.tlpobj");
   rmdir("$tlpobjdir") if $removetlpobjdir;
Index: tlpkg/TeXLive/TLMedia.pm
===================================================================
--- tlpkg/TeXLive/TLMedia.pm	(revision 10611)
+++ 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");
     }