texlive[62794] Master/tlpkg/TeXLive/TLUtils.pm: diskfree for windows

commits+siepo at tug.org commits+siepo at tug.org
Fri Mar 18 22:42:02 CET 2022


Revision: 62794
          http://tug.org/svn/texlive?view=revision&revision=62794
Author:   siepo
Date:     2022-03-18 22:42:01 +0100 (Fri, 18 Mar 2022)
Log Message:
-----------
diskfree for windows >= 8

Modified Paths:
--------------
    trunk/Master/tlpkg/TeXLive/TLUtils.pm

Modified: trunk/Master/tlpkg/TeXLive/TLUtils.pm
===================================================================
--- trunk/Master/tlpkg/TeXLive/TLUtils.pm	2022-03-18 21:03:36 UTC (rev 62793)
+++ trunk/Master/tlpkg/TeXLive/TLUtils.pm	2022-03-18 21:42:01 UTC (rev 62794)
@@ -815,6 +815,42 @@
 
 sub diskfree {
   my $td = shift;
+  my ($output, $retval);
+  if (win32()) {
+    # the powershell one-liner only works from win8 on.
+    my @winver = Win32::GetOSVersion();
+    if ($winver[1]<=6 && $winver[2]<=1) {
+      return -1;
+    }
+    my $avl;
+    if ($td =~ /^[a-zA-Z]:/) {
+      my $drv = substr($td,0,1);
+      # ea ignore: error action ignore: no output at all
+      my $cmd = "powershell -nologo -noninteractive -noprofile -command " .
+       "\"get-psdrive -name $drv -ea ignore |select-object free |format-wide\"";
+      ($output, $retval) = run_cmd($cmd);
+      # ignore exit code, just parse the output
+      my @lines = split(/\r*\n/, $output);
+      foreach (@lines) {
+        chomp $_;
+        if ($_ !~ /^\s*$/) {
+          $_ =~ s/^\s*//;
+          $_ =~ s/\s*$//;
+          $avl = $_;
+          last;
+        }
+      }
+      if ($avl !~ /^[0-9]+$/) {
+        return (-1);
+      } else {
+        return (int($avl/(1024*1024)));
+      }
+    } else {
+      # maybe UNC drive; do not try to handle this
+      return -1;
+    }
+  }
+  # now windows case has been taken care of
   return (-1) if (! $::progs{"df"});
   # drop final /
   $td =~ s!/$!!;
@@ -832,7 +868,7 @@
   $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);
+  ($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



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