changeset 19962:0cc365dada52

Allow tar, unpack, and zip to run on Windows with CR/NL EOL. * tar.m: Don't check for "\n" newline. Use ostrsplit with "\r\n" to split on any EOL char. Use unlink in BIST test, rather than delete, because it will not generate an error. * unpack.m: Don't check for "\n" newline. Use ostrsplit with "\r\n" to split on any EOL char. * zip.m: Don't check for "\n" newline. Use ostrsplit with "\r\n" to split on any EOL char. Use unlink in BIST test, rather than delete, because it will not generate an error.
author Rik <rik@octave.org>
date Tue, 10 Mar 2015 21:23:54 -0700
parents 501cbbaafc56
children e884d5816471
files scripts/miscellaneous/tar.m scripts/miscellaneous/unpack.m scripts/miscellaneous/zip.m
diffstat 3 files changed, 10 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/tar.m	Tue Mar 10 20:37:37 2015 -0700
+++ b/scripts/miscellaneous/tar.m	Tue Mar 10 21:23:54 2015 -0700
@@ -65,10 +65,7 @@
   endif
 
   if (nargout > 0)
-    if (output(end) == "\n")
-      output(end) = [];
-    endif
-    filelist = ostrsplit (output, "\n");
+    filelist = ostrsplit (output, "\r\n", true);
     filelist = filelist';
   endif
 
@@ -117,9 +114,7 @@
 %!   assert (str, "Goodbye World");
 %! unwind_protect_cleanup
 %!   chdir (orig_dir);
-%!   if (exist (tarname))
-%!     delete (tarname);
-%!   endif
+%!   unlink (tarname);
 %!   confirm_recursive_rmdir (false, "local");
 %!   if (exist (dirname))
 %!     rmdir (dirname, "s");
--- a/scripts/miscellaneous/unpack.m	Tue Mar 10 20:37:37 2015 -0700
+++ b/scripts/miscellaneous/unpack.m	Tue Mar 10 21:23:54 2015 -0700
@@ -236,12 +236,8 @@
   endif
 
   if (nargout > 0 || needmove)
-    ## Trim the last CR if needed.
-    ## FIXME: Will this need to change to a check for "\r\n" for windows?
-    if (output(end) == "\n")
-      output(end) = [];
-    endif
-    files = parsefcn (ostrsplit (output, "\n"))';
+    ## Trim the last CR or NL if needed.
+    files = parsefcn (ostrsplit (output, "\r\n", true))';
 
     ## Move files if necessary.
     if (needmove)
--- a/scripts/miscellaneous/zip.m	Tue Mar 10 20:37:37 2015 -0700
+++ b/scripts/miscellaneous/zip.m	Tue Mar 10 21:23:54 2015 -0700
@@ -70,10 +70,7 @@
     if (status)
       error ("zip: zipinfo failed with exit status = %d", status);
     endif
-    if (filelist(end) == "\n")
-      filelist(end) = [];
-    endif
-    filelist = ostrsplit (filelist, "\n");
+    filelist = ostrsplit (filelist, "\r\n", true);
   endif
 
 endfunction
@@ -82,12 +79,12 @@
 %!xtest
 %! ## test zip together with unzip
 %! unwind_protect
-%!   filename = tempname;
+%!   filename = tempname ();
 %!   tmp_var  = pi;
 %!   save (filename, "tmp_var");
-%!   dirname = tempname;
+%!   dirname = tempname ();
 %!   mkdir (dirname);
-%!   zipfile = tempname;
+%!   zipfile = tempname ();
 %!   [~, basename, ext] = fileparts (filename);
 %!   filelist = zip (zipfile, [basename ext], tempdir);
 %!   filelist = filelist{1};
@@ -110,8 +107,8 @@
 %!     error ("unzipped file not equal to original file!");
 %!   endif
 %! unwind_protect_cleanup
-%!   delete (filename);
-%!   delete ([dirname, filesep, basename, extension]);
+%!   unlink (filename);
+%!   unlink ([dirname, filesep, basename, extension]);
 %!   rmdir (dirname);
 %! end_unwind_protect