texlive[62431] Master: installer and free disk space improvements

commits+preining at tug.org commits+preining at tug.org
Sat Mar 5 15:03:21 CET 2022


Revision: 62431
          http://tug.org/svn/texlive?view=revision&revision=62431
Author:   preining
Date:     2022-03-05 15:03:21 +0100 (Sat, 05 Mar 2022)
Log Message:
-----------
installer and free disk space improvements

- factor free disk space computation into a new TLUtils function
- save (and update) the free disk space for the current TEXDIR in %vars
- display the free disk space (if it is available) in the text menu

Modified Paths:
--------------
    trunk/Master/install-tl
    trunk/Master/tlpkg/TeXLive/TLUtils.pm
    trunk/Master/tlpkg/installer/install-menu-text.pl

Modified: trunk/Master/install-tl
===================================================================
--- trunk/Master/install-tl	2022-03-05 08:40:54 UTC (rev 62430)
+++ trunk/Master/install-tl	2022-03-05 14:03:21 UTC (rev 62431)
@@ -907,6 +907,8 @@
   set_texlive_default_dirs();
   set_install_platform();
   initialize_collections();
+  # size information
+  $vars{'free_size'} = TeXLive::TLUtils::diskfree($vars{'TEXDIR'});
 
   # initialize the scheme from the command line value, if given.
   if ($opt_scheme) {
@@ -943,35 +945,13 @@
   if (win32()) {
     TeXLive::TLWinGoo::maybe_make_ro ($vars{'TEXDIR'});
   }
-  # If df is available, check for free disk space
-  if ($::progs{"df"}) {
-    # To ensure that GNU coreutil df returns POSIX style 512-blocks,
-    # it is necessary to set POSIXLY_CORRECT=1
-    # (GNU df defaults to 1024-block)
-    # https://en.wikipedia.org/wiki/POSIX#512-_vs_1024-byte_blocks
-    my $td = $vars{'TEXDIR'};
-    $td .= "/" if ($td !~ m!/$!);
-    debug("Checking for free diskspace in $td\n");
-    my ($output, $retval) =
-      TeXLive::TLUtils::run_cmd("df -P \"$vars{'TEXDIR'}\"",
-                                POSIXLY_CORRECT => 1);
-    if ($retval == 0) {
-      # Output format should be this:
-      # Filesystem      512-blocks       Used  Available Capacity Mounted on
-      # /dev/sdb3       6099908248 3590818104 2406881416      60% /home
-      my ($h,$l) = split(/\n/, $output);
-      my ($fs, $nrb, $used, $avail, @rest) = split(' ', $l);
-      debug("disk space: used=$used (512-block), avail=$avail (512-block),",
-            " required=$vars{'total_size'} (Mb)\n");
-      # $vars{'total_size'} is number required in Mb (1024**2)
-      # $vars{'total_size'} =
-      #   sprintf "%d", ($size * $TeXLive::TLConfig::BlockSize)/1024**2;
-      # $avail is in 512 blocks, so we need to device by 2 * 1024 to obtain Mb
-      # require that at least 100M remain free
-      my $reserve = 100;
-      if ( $avail / 2024 + $reserve < $vars{'total_size'}) {
-        die("DISK SPACE INSUFFICIENT!");
-      }
+  # check for free disk space
+  my $diskfree = TeXLive::TLUtils::diskfree($vars{'TEXDIR'});
+  # -1 is returned if df not available or some other error
+  if ($diskfree != -1) {
+    my $reserve = 100;
+    if ( $diskfree + $reserve < $vars{'total_size'}) {
+      die("DISK SPACE INSUFFICIENT!");
     }
   }
   # now remove final slash from TEXDIR even if it is the root of a drive

Modified: trunk/Master/tlpkg/TeXLive/TLUtils.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLUtils.pm	2022-03-05 08:40:54 UTC (rev 62430)
+++ trunk/Master/tlpkg/TeXLive/TLUtils.pm	2022-03-05 14:03:21 UTC (rev 62431)
@@ -42,6 +42,7 @@
   TeXLive::TLUtils::xsystem(@args);
   TeXLive::TLUtils::run_cmd($cmd [, @envvars ]);
   TeXLive::TLUtils::system_pipe($prog, $infile, $outfile, $removeIn, @args);
+  TeXLive::TLUtils::diskfree($path);
 
 =head2 File utilities
 
@@ -232,6 +233,7 @@
     &xsystem
     &run_cmd
     &system_pipe
+    &diskfree
     &announce_execute_actions
     &add_symlinks
     &remove_symlinks
@@ -258,7 +260,7 @@
   @EXPORT = qw(setup_programs download_file process_logging_options
                tldie tlwarn info log debug ddebug dddebug debug
                debug_hash_str debug_hash
-               win32 xchdir xsystem run_cmd system_pipe sort_archs);
+               win32 xchdir xsystem run_cmd system_pipe diskfree sort_archs);
 }
 
 use Cwd;
@@ -801,6 +803,51 @@
   }
 }
 
+=item C<diskfree($path)>
+
+If a POSIX compliant C<df> program is found, returns the number of
+Mb free at C<$path>, otherwise C<-1>. If C<$path> is not existent, go
+back up to two levels and check if any of the parents exists, and use
+the existing one for computing the disk space.
+
+=cut
+
+sub diskfree {
+  my $td = shift;
+  return (-1) if (! $::progs{"df"});
+  # drop final /
+  $td =~ s!/$!!;
+  if (! -e $td) {
+    my $ptd = dirname($td);
+    if (-e $ptd) {
+      $td = $ptd;
+    } else {
+      my $pptd = dirname($ptd);
+      if (-e $pptd) {
+        $td = $pptd;
+      }
+    }
+  }
+  $td .= "/" if ($td !~ m!/$!);
+  return (-1) if (! -e $td);
+  debug("Checking for free diskspace in $td\n");
+  my ($output, $retval) = run_cmd("df -P \"$td\"", POSIXLY_CORRECT => 1);
+  if ($retval == 0) {
+    # Output format should be this:
+    # Filesystem      512-blocks       Used  Available Capacity Mounted on
+    # /dev/sdb3       6099908248 3590818104 2406881416      60% /home
+    my ($h,$l) = split(/\n/, $output);
+    my ($fs, $nrb, $used, $avail, @rest) = split(' ', $l);
+    debug("disk space: used=$used (512-block), avail=$avail (512-block)\n");
+    # $avail is in 512 blocks, so we need to device by 2 * 1024 to obtain Mb
+    # require that at least 100M remain free
+    return (int($avail / 2024));
+  } else {
+    # error in running df -P out of whatever reason
+    return (-1);
+  }
+}
+
 =back
 
 =head2 File utilities
@@ -2635,7 +2682,7 @@
     # tar needs to be provided by the system, we not even check!
     $::progs{'tar'} = "tar";
 
-    setup_one("unix", "df", undef, "-P", 0);
+    setup_one("unix", "df", undef, "-P .", 0);
 
     if (!defined($platform) || ($platform eq "")) {
       # we assume that we run from uncompressed media, so we can call

Modified: trunk/Master/tlpkg/installer/install-menu-text.pl
===================================================================
--- trunk/Master/tlpkg/installer/install-menu-text.pl	2022-03-05 08:40:54 UTC (rev 62430)
+++ trunk/Master/tlpkg/installer/install-menu-text.pl	2022-03-05 14:03:21 UTC (rev 62431)
@@ -545,6 +545,10 @@
   if ("\u$answer" eq '1' and !$opt_in_place) {
     print "New value for TEXDIR [$vars{'TEXDIR'}]: ";
     $answer = &input_dirname ();
+    # update free space information
+    if ($answer ne $vars{'TEXDIR'}) {
+      $vars{'free_size'} = TeXLive::TLUtils::diskfree($answer);
+    }
     $vars{'TEXDIR'} = $answer if $answer ne "";
     my $texdirnoslash;
     if ($vars{'TEXDIR'}=~/^(.*)\/$texlive_release$/) {
@@ -1035,6 +1039,7 @@
   }
 
   clear_screen;
+  my $freestring = ($vars{'free_size'} >= 0 ? " (free: $vars{'free_size'} MB)" : "");
   print <<"EOF";
 ======================> TeX Live installation procedure <=====================
 
@@ -1053,7 +1058,7 @@
  <S> set installation scheme: $vars{'selected_scheme'}
 
  <C> set installation collections:
-     $vars{'n_collections_selected'} collections out of $vars{'n_collections_available'}, disk space required: $vars{'total_size'} MB
+     $vars{'n_collections_selected'} collections out of $vars{'n_collections_available'}, disk space required: $vars{'total_size'} MB$freestring
 EOF
 
   }



More information about the tex-live-commits mailing list.