summaryrefslogtreecommitdiff
path: root/Master/tlpkg/etc/tlmgr-use-saved-remote-tlpdb.patch
blob: 4f52da053d5acde919bf97bae117d3e37583c486 (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
Index: tlmgr.pl
===================================================================
--- tlmgr.pl	(revision 11008)
+++ tlmgr.pl	(working copy)
@@ -79,6 +79,7 @@
 use Cwd qw/abs_path/;
 use Pod::Usage;
 use Getopt::Long qw(:config no_autoabbrev require_order);
+use Digest::MD5 qw(md5_hex);
 use strict;
 
 # used variables
@@ -1864,14 +1865,52 @@
 # uses the global $location.
 #
 sub init_tlmedia {
+  # compute the md5 digest for the location
+  my $locmdv = md5_hey($location);
   if (($location =~ m/$TeXLiveServerURL/) ||
       ($location =~ m/^ctan$/i)) {
     $location = give_ctan_mirror();
   }
   info("tlmgr: installation location $location\n");
+  if ($location =~ m/^(http|ftp):/i) {
+    # try to download the md5hash from the location 
+    my $root = $localtlpdb->root;
+    my $temp = "$root/temp";
+    my $remotefilemdvfile = "$temp/md5.$locmdv";
+    my $remote_tlpdb_copy = "$root/$InfraLocation/texlive.tlpdb.$locmdv";
+    my $ret = TeXLive::TLUtils::download_file("$location/$InfraLocation/${DatabaseName}.md5", "$remotefilemdvfile");
+    if ($ret && (-r "$lzmafile")) {
+      # we found a md5 hash
+      # we have to check the md5hash against the md5 hash of the local file
+      my $local_digest = TeXLive::TLUtils::tlmd5("$remote_tlpdb_copy");
+      if (open (FOO, "<$remotefilemdvfile")) {
+        my $remote_digest = <FOO>;
+        close(FOO);
+        if ($remote_digest eq $local_digest) {
+          # that is fine, we have the same database, don't re-download it
+          $tlmediasrc = TeXLive::TLMedia->new($location, $remote_tlpdb_copy, "good");
+          die ("NOT KNOW WHY") unless defined($tlmediasrc);
+        }
+      } else {
+        debug("Cannot read md5 sum from downloaded file $remotefilemdvfile\n");
+        # we will read it again
+      }
+    } else {
+      tlwarn("We seem to be off line.\n");
+      if (-r "$remote_tlpdb_copy") {
+        tlwarn("Using local copy of remote database, installation may not succeed.\n");
+        $tlmediasrc = TeXLive::TLMedia->new($location, $remote_tlpdb_copy, "maybe_good");
+        die ("NOT KNOW WHY") unless defined($tlmediasrc);
+      } else {
+        # do nothing, we will try below to download the tlpdb ...
+      }
+    }
+  }
   # $tlmediasrc is a global variable
-  $tlmediasrc = TeXLive::TLMedia->new($location);
+  $tlmediasrc = TeXLive::TLMedia->new($location) unless defined($tlmediasrc);
   die($loadmediasrcerror . $location) unless defined($tlmediasrc);
+  # save the md5hash of 
+  tlwarn("TODO TODO TODO ....");
 }
 
 #