changeset 24096:8f3db1ac7877

tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095) * tar.m: Add unwind_protect block to save and restore the TAR_OPTIONS environment variable. * unpack.m: Save and restore the TAR_OPTIONS environment variable within the existing unwind_protect block.
author Mike Miller <mtmiller@octave.org>
date Sun, 24 Sep 2017 13:01:31 -0700
parents eadaf557ca09
children f3b60734ac9b
files scripts/miscellaneous/tar.m scripts/miscellaneous/unpack.m
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/tar.m	Sun Sep 24 11:52:02 2017 -0700
+++ b/scripts/miscellaneous/tar.m	Sun Sep 24 13:01:31 2017 -0700
@@ -63,7 +63,16 @@
   cmd = sprintf ("tar cvf %s -C %s %s",
                           tarfile, rootdir, sprintf (" %s", files{:}));
 
-  [status, output] = system (cmd);
+  ## Save and restore the TAR_OPTIONS environment variable used by GNU tar.
+  tar_options_env = getenv ("TAR_OPTIONS");
+  unwind_protect
+    unsetenv ("TAR_OPTIONS");
+    [status, output] = system (cmd);
+  unwind_protect_cleanup
+    if (! isempty (tar_options_env))
+      setenv ("TAR_OPTIONS", tar_options_env);
+    endif
+  end_unwind_protect
 
   if (status)
     error ("tar: tar exited with status = %d", status);
--- a/scripts/miscellaneous/unpack.m	Sun Sep 24 11:52:02 2017 -0700
+++ b/scripts/miscellaneous/unpack.m	Sun Sep 24 13:01:31 2017 -0700
@@ -240,11 +240,17 @@
     error ("unpack: %s: not a directory", dir);
   endif
 
+  ## Save and restore the TAR_OPTIONS environment variable used by GNU tar.
+  tar_options_env = getenv ("TAR_OPTIONS");
   unwind_protect
+    unsetenv ("TAR_OPTIONS");
     cd (dir);
     [status, output] = system (sprintf ([command " 2>&1"], file));
   unwind_protect_cleanup
     cd (origdir);
+    if (! isempty (tar_options_env))
+      setenv ("TAR_OPTIONS", tar_options_env);
+    endif
   end_unwind_protect
 
   if (status)