From a51c1d616ca61bc07fe9c68c41531b70a1126dec Mon Sep 17 00:00:00 2001
From: Mike Dalessio <mike@37signals.com>
Date: Thu, 14 Nov 2024 14:20:43 -0500
Subject: [PATCH] Check for the existence of xzcat

and emit a readable error if it doesn't exist
---
 lib/mini_portile2/mini_portile.rb | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/mini_portile2/mini_portile.rb b/lib/mini_portile2/mini_portile.rb
index 0607d3f..c4a1db8 100644
--- a/lib/mini_portile2/mini_portile.rb
+++ b/lib/mini_portile2/mini_portile.rb
@@ -553,6 +553,10 @@ def tar_exe
     end
   end
 
+  def xzcat_exe
+    @@xzcat_exe ||= which("xzcat") ? "xzcat" : raise("xzcat not found")
+  end
+
   def tar_command(file, target)
     case File.extname(file)
       when '.gz', '.tgz'
@@ -561,7 +565,7 @@ def tar_command(file, target)
         [tar_exe, 'xjf', file, '-C', target]
       when '.xz'
         # NOTE: OpenBSD's tar command does not support the -J option
-        "xzcat #{file.shellescape} | #{tar_exe.shellescape} xf - -C #{target.shellescape}"
+        "#{xzcat_exe.shellescape} #{file.shellescape} | #{tar_exe.shellescape} xf - -C #{target.shellescape}"
       else
         [tar_exe, 'xf', file, '-C', target]
     end