[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: untar.m on Solaris with non-GNU tar
From: |
Bill Denney |
Subject: |
Re: untar.m on Solaris with non-GNU tar |
Date: |
Fri, 20 Oct 2006 20:51:02 -0400 |
User-agent: |
Thunderbird 1.5.0.7 (Windows/20060909) |
Bill Denney wrote:
John W. Eaton wrote:
On 20-Oct-2006, Bill Denney wrote:
| unwind_protect
| cd (directory);
| [status, output] = system (sprintf ([command " 2>&1"], file));
| cd (origdir);
| unwind_protect_cleanup
| cd (origdir);
| end_unwind_protect
The cleanup code in an unwind_protect block is always executed, so the
above code does "cd (origdir") twice.
OK, I've attached a version with those changes.
I forgot to attach the related functions.
Bill
scripts/ChangeLog:
2006-10-20 Bill Denney <address@hidden>
* miscellaneous/untar.m, miscellaneous/gunzip.m,
miscellaneous/bunzip2.m, miscellaneous/unzip.m: use unpack.m to unpack files
## Copyright (C) 2006 Bill Denney
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING. If not, write to the Free
## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
## -*- texinfo -*-
## @deftypefn {Function File} bunzip2 (@var{bzfile}, @var{dir})
## Unpack the bzip2 archive @var{bzfile} to the directory @var{dir}. If
## @var{dir} is not specified, it defaults to the current directory.
## @seealso{unpack, bzip2, tar, untar, gzip, gunzip, zip, unzip}
## @end deftypefn
## Author: Bill Denney <address@hidden>
function files = bunzip2 (varargin)
if ! (nargin == 1 || nargin == 2)
print_usage ();
endif
args = varargin;
if (nargin < 2)
args{2} = ".";
endif
f = unpack (args{:}, "bunzip2");
if nargout > 0
files = f;
endif
endfunction
## Copyright (C) 2005 Søren Hauberg
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING. If not, write to the Free
## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
## -*- texinfo -*-
## @deftypefn {Function File} gunzip (@var{gzfile}, @var{dir})
## Unpack the gzip archive @var{gzfile} to the directory @var{dir}. If
## @var{dir} is not specified, it defaults to the current directory. If
## the @var{gzfile} is a directory, all files in the directory will be
## recursively gunzipped.
## @seealso{unpack, bzip2, bunzip2, tar, untar, gzip, gunzip, zip, unzip}
## @end deftypefn
## Author: Søren Hauberg <address@hidden>
## Adapted-By: jwe
function files = gunzip (varargin)
if ! (nargin == 1 || nargin == 2)
print_usage ();
endif
args = varargin;
if (nargin < 2)
args{2} = ".";
endif
f = unpack (args{:}, "gunzip");
if nargout > 0
files = f;
endif
endfunction
Index: untar.m
===================================================================
RCS file: /cvs/octave/scripts/miscellaneous/untar.m,v
retrieving revision 1.4
diff -u -r1.4 untar.m
--- untar.m 13 Oct 2006 14:32:15 -0000 1.4
+++ untar.m 21 Oct 2006 00:46:58 -0000
@@ -21,75 +21,25 @@
## @deftypefn {Function File} untar (@var{tarfile}, @var{dir})
## Unpack the TAR archive @var{tarfile} to the directory @var{dir}.
## If @var{dir} is not specified, it defaults to the current directory.
-## @seealso{tar, gzip, gunzip, zip, unzip}
+## @seealso{unpack, bzip2, bunzip2, tar, gzip, gunzip, zip, unzip}
## @end deftypefn
## Author: Søren Hauberg <address@hidden>
## Adapted-By: jwe
-function files = untar (tarfile, directory)
+function files = untar (varargin)
- if (nargin == 1 || nargin == 2)
-
- if (nargin == 1)
- directory = ".";
- endif
-
- ## 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 (directory);
- if (isempty (s))
- [status, msg] = mkdir (directory);
- if (! status)
- error ("untar: mkdir failed to create %s: %s", directory, msg);
- endif
- elseif (! S_ISDIR (s.mode))
- error ("untar: %s: not a directory", directory);
- endif
-
- unwind_protect
- chdir (directory);
- [status, output] = system (sprintf ("tar -x -v -f %s", tarfile));
- unwind_protect_cleanup
- chdir (orig_dir);
- end_unwind_protect
-
- if (status == 0)
- if (nargout > 0)
- fs = filesep ();
- if (directory(end) != fs)
- directory = strcat (directory, fs);
- endif
- ## Sadly not reliable if a filename contains a newline
- ## character!
- if (output(end) == "\n")
- output(end) = [];
- endif
- files = cellstr (split (output, "\n"));
- if (! strcmp (directory, "."))
- nf = length (files);
- for i = 1:nf
- files{i} = strcat (directory, files{i});
- endfor
- endif
- files = files';
- endif
- else
- error ("tar: tar exited with status = %s", status);
- endif
-
- else
- error ("untar: expecting arguments to be character strings");
- endif
+ if ! (nargin == 1 || nargin == 2)
+ print_usage ();
+ endif
- else
- print_usage ("untar");
+ args = varargin;
+ if (nargin < 2)
+ args{2} = ".";
+ endif
+ f = unpack (args{:}, "untar");
+ if nargout > 0
+ files = f;
endif
endfunction
Index: unzip.m
===================================================================
RCS file: /cvs/octave/scripts/miscellaneous/unzip.m,v
retrieving revision 1.3
diff -u -r1.3 unzip.m
--- unzip.m 13 Oct 2006 14:32:15 -0000 1.3
+++ unzip.m 21 Oct 2006 00:46:58 -0000
@@ -21,41 +21,25 @@
## @deftypefn {Function File} unzip (@var{zipfile}, @var{dir})
## Unpack the ZIP archive @var{zipfile} to the directory @var{dir}.
## If @var{dir} is not specified, it defaults to the current directory.
-## @seealso{tar, untar, gzip, gunzip, zip}
+## @seealso{unpack, tar, untar, gzip, gunzip, zip}
## @end deftypefn
## Author: Søren Hauberg <address@hidden>
## Adapted-By: jwe
-function files = unzip (zipfile, dir)
+function files = unzip (varargin)
- if (nargin == 1 || nargin == 2)
-
- if (nargin == 1)
- dir = ".";
- endif
-
- if (ischar (zipfile) && ischar (dir))
-
- [status, output] = system (sprintf ("unzip %s -d %s", zipfile, dir));
-
- if (status == 0)
- if (nargout > 0)
- ## Create list of extracted files. It blows that there seems
- ## to be no way to get unzip to print a simple list of file
- ## names.
- files = strrep (output, " inflating: ", "");
- files = cellstr (split (files, "\n"));
- files = files(2:end-1,:);
- files = files';
- endif
- else
- error ("unzip: unzip exited with status = %d", status);
- endif
- endif
+ if ! (nargin == 1 || nargin == 2)
+ print_usage ();
+ endif
- else
- print_usage ("unzip");
+ args = varargin;
+ if (nargin < 2)
+ args{2} = ".";
+ endif
+ f = unpack (args{:}, "unzip");
+ if nargout > 0
+ files = f;
endif
endfunction
- untar.m on Solaris with non-GNU tar, John Swensen, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar, Bill Denney, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar, John W. Eaton, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar, Bill Denney, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar,
Bill Denney <=
- Re: untar.m on Solaris with non-GNU tar, John W. Eaton, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar, Bill Denney, 2006/10/20
- Re: untar.m on Solaris with non-GNU tar, John W. Eaton, 2006/10/24
- Re: untar.m on Solaris with non-GNU tar, Bill Denney, 2006/10/24
- Re: untar.m on Solaris with non-GNU tar, John W. Eaton, 2006/10/24