changeset 21525:50255c612915

Fix zip, gzip, bzip2 to allow names with spaces (bug #47232). * zip.m: Expand out wildcards with glob(), escape double quotes with regexprep, and then wrap file names in double quotes before passing to zip command via the shell. * __xzip__.m: Wrap file names in double quotes before passing through shell.
author Rik <rik@octave.org>
date Tue, 22 Mar 2016 14:25:35 -0700
parents aac8b2ca9280
children b76d1de20f9a
files scripts/miscellaneous/private/__xzip__.m scripts/miscellaneous/zip.m
diffstat 2 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/private/__xzip__.m	Sat Mar 19 14:29:55 2016 -0400
+++ b/scripts/miscellaneous/private/__xzip__.m	Tue Mar 22 14:25:35 2016 -0700
@@ -70,7 +70,7 @@
 
     cd (outdir);
 
-    cmd = sprintf (commandtemplate, sprintf (" %s", fnames{:}));
+    cmd = sprintf (commandtemplate, sprintf (' "%s"', fnames{:}));
 
     [status, output] = system (cmd);
     if (status)
--- a/scripts/miscellaneous/zip.m	Sat Mar 19 14:29:55 2016 -0400
+++ b/scripts/miscellaneous/zip.m	Tue Mar 22 14:25:35 2016 -0700
@@ -55,7 +55,11 @@
 
   zipfile = make_absolute_filename (zipfile);
 
-  cmd = sprintf ("zip -r %s %s", zipfile, sprintf (" %s", files{:}));
+  files = glob (files);                   # expand wildcards
+  files = regexprep (files, '"', '\\"');  # escape double quotes
+  files = sprintf (' "%s"', files{:});    # convert to space separated list
+  zipfile = regexprep (zipfile, '"', '\\"');  # escape double quotes
+  cmd = sprintf ('zip -r "%s" %s', zipfile, files);
 
   origdir = pwd ();
   cd (rootdir);