octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

untar Patch


From: Bill Denney
Subject: untar Patch
Date: Sun, 08 Oct 2006 17:33:08 -0400
User-agent: Thunderbird 1.5.0.7 (Windows/20060909)

In a related patch, to the pkg patch from earlier, I accidentally gave an invalid filename to pkg earlier, and untar didn't catch this. Here is a patch that should catch any problems from untar.

Bill

2006-10-08  Bill Denney  <address@hidden>
scripts/Changelog:

* miscellaneous/untar.m: check more rigorously to see if the file exists.
Index: untar.m
===================================================================
RCS file: /cvs/octave/scripts/miscellaneous/untar.m,v
retrieving revision 1.2
diff -u -r1.2 untar.m
--- untar.m     11 May 2006 03:11:03 -0000      1.2
+++ untar.m     8 Oct 2006 21:30:36 -0000
@@ -24,32 +24,34 @@
 ## Author: Søren Hauberg <address@hidden>
 ## Adapted-By: jwe
 
-function files = untar (tarfile, dir)
+function files = untar (tarfile, directory)
 
   if (nargin == 1 || nargin == 2)
 
     if (nargin == 1)
-      dir = ".";
+      directory = ".";
     endif
 
-    if (ischar (tarfile) && ischar (dir))
+    ## the file must exist (and be a file) and the directory must be a
+    ## string
+    if (exist (tarfile, "file") && ischar (directory))
 
       orig_dir = pwd ();
 
       tarfile = canonicalize_file_name (tarfile);
 
-      s = stat (dir);
+      s = stat (directory);
       if (isempty (s))
-       [status, msg] = mkdir (dir);
+       [status, msg] = mkdir (directory);
        if (! status)
-         error ("untar: mkdir failed to create %s: %s", dir, msg);
+         error ("untar: mkdir failed to create %s: %s", directory, msg);
        endif
       elseif (! S_ISDIR (s.mode))
-       error ("untar: %s: not a directory", dir);
+       error ("untar: %s: not a directory", directory);
       endif
 
       unwind_protect
-       chdir (dir);
+       chdir (directory);
        [status, output] = system (sprintf ("tar -x -v -f %s", tarfile));
       unwind_protect_cleanup
        chdir (orig_dir);
@@ -58,8 +60,8 @@
       if (status == 0)
        if (nargout > 0)
          fs = filesep ();
-         if (dir(end) != fs)
-           dir = strcat (dir, fs);
+         if (directory(end) != fs)
+           directory = strcat (directory, fs);
          endif
          ## Sadly not reliable if a filename contains a newline
          ## character!
@@ -67,10 +69,10 @@
            output(end) = [];
          endif
          files = cellstr (split (output, "\n"));
-         if (! strcmp (dir, "."))
+         if (! strcmp (directory, "."))
            nf = length (files);
            for i = 1:nf
-             files{i} = strcat (dir, files{i});
+             files{i} = strcat (directory, files{i});
            endfor
          endif
          files = files';

reply via email to

[Prev in Thread] Current Thread [Next in Thread]