proper treatment of tar.gz double-extension;
authorwenzelm
Fri, 25 Nov 2022 20:17:54 +0100
changeset 76533 2590980401b0
parent 76532 c9e1276f0268
child 76534 69139cc01ba1
proper treatment of tar.gz double-extension;
src/Pure/General/file.scala
src/Pure/System/isabelle_system.scala
--- a/src/Pure/General/file.scala	Fri Nov 25 16:20:14 2022 +0100
+++ b/src/Pure/General/file.scala	Fri Nov 25 20:17:54 2022 +0100
@@ -83,6 +83,7 @@
   def is_node(s: String): Boolean = s.endsWith(".node")
   def is_pdf(s: String): Boolean = s.endsWith(".pdf")
   def is_png(s: String): Boolean = s.endsWith(".png")
+  def is_tar_gz(s: String): Boolean = s.endsWith(".tar.gz")
   def is_thy(s: String): Boolean = s.endsWith(".thy")
   def is_xz(s: String): Boolean = s.endsWith(".xz")
   def is_zip(s: String): Boolean = s.endsWith(".zip")
--- a/src/Pure/System/isabelle_system.scala	Fri Nov 25 16:20:14 2022 +0100
+++ b/src/Pure/System/isabelle_system.scala	Fri Nov 25 20:17:54 2022 +0100
@@ -433,14 +433,16 @@
     else error("Expected to find GNU tar executable")
   }
 
-  def extract(archive: Path, dir: Path): Unit =
-    archive.get_ext match {
-      case "zip" =>
-        Isabelle_System.bash("unzip -x " + File.bash_path(archive.absolute), cwd = dir.file).check
-      case "tar.gz" | "tgz" =>
-        Isabelle_System.gnutar("-xzf " + File.bash_path(archive), dir = dir).check
-      case _ => error("Cannot extract " + archive)
+  def extract(archive: Path, dir: Path): Unit = {
+    val name = archive.file_name
+    if (File.is_zip(name)) {
+      Isabelle_System.bash("unzip -x " + File.bash_path(archive.absolute), cwd = dir.file).check
     }
+    else if (File.is_tar_gz(name)) {
+      Isabelle_System.gnutar("-xzf " + File.bash_path(archive), dir = dir).check
+    }
+    else error("Cannot extract " + archive)
+  }
 
   def make_patch(base_dir: Path, src: Path, dst: Path, diff_options: String = ""): String = {
     with_tmp_file("patch") { patch =>