Mercurial > octave
annotate scripts/miscellaneous/unpack.m @ 27978:a4268efb7334
maint: Eliminate single "Author:" lines from code base.
* color-picker.cc, color-picker.h, octave-qscintilla.cc, octave-qscintilla.h,
octave-txt-lexer.cc, octave-txt-lexer.h, balance.cc, kron.cc, lookup.cc,
ls-hdf5.cc, ls-mat5.cc, ls-oct-text.cc, sylvester.cc, tsearch.cc, jit-ir.cc,
jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, jit-util.cc, jit-util.h, pt-jit.cc,
pt-jit.h, Array-jit.cc, bsxfun.h, url-transfer.cc, url-transfer.h, acosd.m,
acotd.m, acscd.m, asecd.m, asind.m, atand.m, cosd.m, cotd.m, cscd.m, secd.m,
sind.m, tand.m, cart2pol.m, cart2sph.m, curl.m, del2.m, divergence.m, flip.m,
pol2cart.m, randi.m, sortrows.m, sph2cart.m, griddata3.m, griddatan.m,
rectint.m, voronoi.m, dialog.m, guidata.m, guihandles.m, __file_filter__.m,
__fltk_file_filter__.m, __get_funcname__.m, __is_function__.m,
__uigetdir_fltk__.m, __uigetfile_fltk__.m, __uiobject_split_args__.m,
__uiputfile_fltk__.m, uibuttongroup.m, uicontextmenu.m, uicontrol.m,
uigetdir.m, uigetfile.m, uimenu.m, uipanel.m, uipushtool.m, uiputfile.m,
uiresume.m, uitoggletool.m, uitoolbar.m, uiwait.m, doc.m, autumn.m, bone.m,
cmpermute.m, cmunique.m, cool.m, copper.m, cubehelix.m, flag.m, frame2im.m,
hot.m, hsv.m, hsv2rgb.m, im2frame.m, imfinfo.m, imformats.m, iscolormap.m,
jet.m, pink.m, prism.m, __imfinfo__.m, rainbow.m, rgb2hsv.m, spinmap.m,
spring.m, viridis.m, white.m, winter.m, importdata.m, strmatch.m, bandwidth.m,
isbanded.m, isdiag.m, istril.m, istriu.m, krylov.m, linsolve.m, logm.m,
lscov.m, subspace.m, bunzip2.m, compare_versions.m, edit.m, fullfile.m,
getfield.m, gunzip.m, inputParser.m, license.m, nargchk.m, narginchk.m,
nthargout.m, python.m, setfield.m, tar.m, unpack.m, ver.m, zip.m, odeplot.m,
fminbnd.m, fminunc.m, fsolve.m, fzero.m, glpk.m, humps.m, pathdef.m,
savepath.m, diffuse.m, lighting.m, material.m, shading.m, specular.m,
contour.m, ellipsoid.m, isocaps.m, isocolors.m, isonormals.m, isosurface.m,
light.m, pcolor.m, __interp_cube__.m, __marching_cube__.m, __patch__.m,
__stem__.m, reducepatch.m, reducevolume.m, ribbon.m, shrinkfaces.m, slice.m,
stem.m, surf.m, surfl.m, tetramesh.m, waterfall.m, __actual_axis_position__.m,
__next_line_color__.m, allchild.m, figure.m, findall.m, findobj.m, gcf.m,
hggroup.m, isprop.m, ndgrid.m, __add_default_menu__.m, saveas.m,
__splinefit__.m, prefdir.m, preferences.m, profexplore.m, profexport.m,
profile.m, profshow.m, setdiff.m, freqz.m, freqz_plot.m, sinc.m, unwrap.m,
pcr.m, qmr.m, sprandn.m, betaincinv.m, cosint.m, ellipke.m, factor.m,
gammaincinv.m, legendre.m, nchoosek.m, primes.m, invhilb.m, toeplitz.m,
erase.m, mat2str.m, strtrim.m, validatestring.m, fail.m, compare_plot_demos.m,
dump_demos.m, html_compare_plot_demos.m, addtodate.m, datenum.m, jit.tst:
Eliminate single "Author:" lines from code base.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 21 Jan 2020 12:53:13 -0800 |
parents | bd51beb6205e |
children | 9cb04a9e81ec 0a5b15007766 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 2006-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27569
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
7 ## |
6082 | 8 ## This file is part of Octave. |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24096
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
6082 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24096
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22511
diff
changeset
|
13 ## (at your option) any later version. |
6082 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22511
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22511
diff
changeset
|
18 ## GNU General Public License for more details. |
6082 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24096
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
6082 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20755
diff
changeset
|
27 ## @deftypefn {} {@var{files} =} unpack (@var{file}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20755
diff
changeset
|
28 ## @deftypefnx {} {@var{files} =} unpack (@var{file}, @var{dir}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20755
diff
changeset
|
29 ## @deftypefnx {} {@var{files} =} unpack (@var{file}, @var{dir}, @var{filetype}) |
6082 | 30 ## Unpack the archive @var{file} based on its extension to the directory |
19234 | 31 ## @var{dir}. |
32 ## | |
33 ## If @var{file} is a list of strings, then each file is unpacked | |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19951
diff
changeset
|
34 ## individually. Shell wildcards in the filename such as @samp{*} or |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19951
diff
changeset
|
35 ## @samp{?} are accepted and expanded. |
19234 | 36 ## |
37 ## If @var{dir} is not specified or is empty (@code{[]}), it defaults to the | |
38 ## current directory. If a directory is in the file list, then @var{filetype} | |
39 ## must also be specified. | |
40 ## | |
41 ## The specific archive filetype is inferred from the extension of the file. | |
42 ## The @var{filetype} may also be specified directly using a string which | |
43 ## corresponds to a known extension. | |
44 ## | |
45 ## Valid filetype extensions: | |
46 ## | |
47 ## @table @code | |
25003
2365c2661b3c
doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24662
diff
changeset
|
48 ## @item @nospell{bz} |
2365c2661b3c
doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24662
diff
changeset
|
49 ## @itemx @nospell{bz2} |
19234 | 50 ## bzip archive |
51 ## | |
25003
2365c2661b3c
doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents:
24662
diff
changeset
|
52 ## @item @nospell{gz} |
19234 | 53 ## gzip archive |
54 ## | |
55 ## @item tar | |
56 ## tar archive | |
57 ## | |
58 ## @item tarbz | |
19235
cac9d4c49522
unpack.m: Fix Texinfo error in docstring.
Rik <rik@octave.org>
parents:
19234
diff
changeset
|
59 ## @itemx tarbz2 |
19234 | 60 ## @itemx tbz |
61 ## @itemx tbz2 | |
62 ## tar + bzip archive | |
63 ## | |
64 ## @item targz | |
65 ## @itemx tgz | |
66 ## tar + gzip archive | |
67 ## | |
68 ## @item z | |
69 ## compress archive | |
70 ## | |
71 ## @item zip | |
72 ## zip archive | |
73 ## @end table | |
6082 | 74 ## |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12500
diff
changeset
|
75 ## The optional return value is a list of @var{files} unpacked. |
19243 | 76 ## @seealso{bunzip2, gunzip, unzip, untar, bzip2, gzip, zip, tar} |
6082 | 77 ## @end deftypefn |
78 | |
26142
b9d72a2dac8f
Accept a cell array of strings to uncompress functions (bug #55102).
Rik <rik@octave.org>
parents:
25948
diff
changeset
|
79 function filelist = unpack (file, dir = [], filetype = "") |
6082 | 80 |
81 if (nargin < 1 || nargin > 3) | |
82 print_usage (); | |
83 endif | |
84 | |
19234 | 85 if (! ischar (file) && ! iscellstr (file)) |
86 error ("unpack: FILE must be a string or cell array of strings"); | |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
87 endif |
6082 | 88 |
19234 | 89 ## Convert char arrays to cell strings to simplify further processing |
90 if (ischar (file)) | |
91 file = cellstr (file); | |
92 endif | |
93 if (numel (file) == 1) | |
25885
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
94 ## FIXME: The code below is not a perfect test for a URL |
20748
bb219f1d92db
Fix indexing error in cset 69aeef6736df.
Rik <rik@octave.org>
parents:
20746
diff
changeset
|
95 if (isempty (strfind (file{1}, "://"))) |
20746
69aeef6736df
unpack.m: Restore ability for input to be a URL (bug #46504).
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
96 gfile = glob (file); |
69aeef6736df
unpack.m: Restore ability for input to be a URL (bug #46504).
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
97 if (isempty (gfile)) |
22760
c4d80b9d2898
maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
98 error ('unpack: FILE "%s" not found', file{1}); |
20746
69aeef6736df
unpack.m: Restore ability for input to be a URL (bug #46504).
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
99 else |
69aeef6736df
unpack.m: Restore ability for input to be a URL (bug #46504).
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
100 file = gfile; |
69aeef6736df
unpack.m: Restore ability for input to be a URL (bug #46504).
Rik <rik@octave.org>
parents:
20713
diff
changeset
|
101 endif |
19234 | 102 endif |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
103 endif |
6082 | 104 |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
105 ## Recursively unpack cellstr arrays one file at a time |
19234 | 106 if (numel (file) > 1) |
6082 | 107 files = {}; |
108 for i = 1:numel (file) | |
26142
b9d72a2dac8f
Accept a cell array of strings to uncompress functions (bug #55102).
Rik <rik@octave.org>
parents:
25948
diff
changeset
|
109 if (! isempty (dir)) |
b9d72a2dac8f
Accept a cell array of strings to uncompress functions (bug #55102).
Rik <rik@octave.org>
parents:
25948
diff
changeset
|
110 tmpfiles = unpack (file{i}, dir); |
b9d72a2dac8f
Accept a cell array of strings to uncompress functions (bug #55102).
Rik <rik@octave.org>
parents:
25948
diff
changeset
|
111 else |
b9d72a2dac8f
Accept a cell array of strings to uncompress functions (bug #55102).
Rik <rik@octave.org>
parents:
25948
diff
changeset
|
112 tmpfiles = unpack (file{i}, fileparts (file{i})); |
b9d72a2dac8f
Accept a cell array of strings to uncompress functions (bug #55102).
Rik <rik@octave.org>
parents:
25948
diff
changeset
|
113 endif |
6082 | 114 files = {files{:} tmpfiles{:}}; |
115 endfor | |
116 | |
8352
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
117 ## Return output if requested. |
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
118 if (nargout > 0) |
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
119 filelist = files; |
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
120 endif |
19234 | 121 return; |
8352
33337f1aca75
fix bug in cell string handling of unpack function
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
8297
diff
changeset
|
122 |
19233
0ded8964c13a
Added wildcard * support to archive-related routines (bug #43211).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
18857
diff
changeset
|
123 else |
19234 | 124 file = file{1}; |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
125 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
126 |
25885
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
127 if (nargin == 3 && (! ischar (filetype) || ! isrow (filetype))) |
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
128 error ("unpack: FILETYPE must be a string"); |
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
129 endif |
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
130 |
25781
e04c56bbbace
isdir.m: Make m-file a legacy function (bug #54489)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
131 if (isfolder (file)) |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
132 if (isempty (filetype)) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
133 error ("unpack: FILETYPE must be given for a directory"); |
25885
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
134 elseif (! strcmpi (filetype, "gz")) |
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
135 error ('unpack: FILETYPE must be "gz" for a directory'); |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
136 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
137 ext = ".gz"; |
6082 | 138 else |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
139 [pathstr, name, ext] = fileparts (file); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
140 |
25885
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
141 if (nargin == 3 && ! strcmpi (ext, filetype)) |
25948
700b3f415ebe
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
25893
diff
changeset
|
142 ## override extension with given filetype |
25885
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
143 if (isempty (ext)) |
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
144 ext = filetype; |
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
145 else |
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
146 ext = regexprep (ext, '(\.?)\S*$', ['$1' filetype]); |
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
147 endif |
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
148 endif |
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
149 |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
150 ## Check to see if it's .tar.gz, .tar.Z, etc. |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
151 if (any (strcmpi ({".gz" ".Z" ".bz2" ".bz"}, ext))) |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
152 [~, tmpname, tmpext] = fileparts (name); |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
153 if (strcmpi (tmpext, ".tar")) |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
154 name = tmpname; |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
155 ext = [tmpext ext]; |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
156 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
157 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
158 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
159 ## If the file is a URL, download it and then work with that file. |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
160 if (! isempty (strfind (file, "://"))) |
19234 | 161 ## FIXME: The above code is not a perfect test for a URL |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
162 urlfile = file; |
20755
46b15c018fa5
unpack.m: Fix handling of gzip archives expanded into /tmp (bug #40274).
Rik <rik@octave.org>
parents:
20748
diff
changeset
|
163 tmpfile = fullfile (tempdir (), [name ext]); |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
164 [file, success, msg] = urlwrite (urlfile, tmpfile); |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
165 if (! success) |
19234 | 166 error ('unpack: could not fetch "%s": %s', urlfile, msg); |
12499
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
167 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
168 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
169 |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
170 endif |
a3019189ac51
Improve file archiving functions (gzip, bzip2, zip, unpack)
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
171 |
19579
0cc52d752f99
unpack.m: replace canonicalize_file_name by make_absolute_filename (bug #43979)
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
19278
diff
changeset
|
172 file = make_absolute_filename (file); |
6082 | 173 |
20291
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
174 if (isempty (dir)) |
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
175 dir = "."; |
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
176 else |
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
177 dir = tilde_expand (dir); |
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
178 endif |
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
179 |
6082 | 180 ## Instructions on what to do for any extension. |
181 ## | |
182 ## The field names are the file extension without periods. | |
183 ## The first cell is what is executed to unpack an archive verbosely. | |
184 ## The second cell is what is executed to unpack an archive quietly. | |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
185 ## The third cell is the function to execute on output to get the files list. |
6082 | 186 ## The fourth cell indicates if the files may need to be manually moved |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
187 ## (i.e., tar and unzip decompress into the current directory while |
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
188 ## bzip2 and gzip decompress the file at its location). |
6082 | 189 persistent commandlist; |
190 if (isempty (commandlist)) | |
20291
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
191 commandlist.gz = {'gzip -d -v -f -r "%s"', ... |
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
192 'gzip -d -f -r "%s"', ... |
10549 | 193 @__parse_gzip__, true}; |
6082 | 194 commandlist.z = commandlist.gz; |
20291
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
195 commandlist.bz2 = {'bzip2 -d -v -f "%s"', ... |
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
196 'bzip2 -d -f "%s"', ... |
10549 | 197 @__parse_bzip2__, true}; |
6082 | 198 commandlist.bz = commandlist.bz2; |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
199 commandlist.tar = {'tar xvf "%s"', ... |
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
200 'tar xf "%s"', ... |
10549 | 201 @__parse_tar__, false}; |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
202 commandlist.targz = {'gzip -d -c "%s" | tar xvf -', ... |
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
203 'gzip -d -c "%s" | tar xf -', ... |
10549 | 204 @__parse_tar__, false}; |
6082 | 205 commandlist.tgz = commandlist.targz; |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
206 commandlist.tarbz2 = {'bzip2 -d -c "%s" | tar xvf -', ... |
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
207 'bzip2 -d -c "%s" | tar xf -', ... |
10549 | 208 @__parse_tar__, false}; |
6082 | 209 commandlist.tarbz = commandlist.tarbz2; |
210 commandlist.tbz2 = commandlist.tarbz2; | |
211 commandlist.tbz = commandlist.tarbz2; | |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
212 commandlist.zip = {'unzip -n "%s"', ... |
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
213 'unzip -nq "%s"', ... |
10549 | 214 @__parse_zip__, false}; |
6082 | 215 endif |
216 | |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
217 ## Unzip doesn't actually care about the extension |
25885
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
218 if (strcmpi (filetype, "zip")) |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
219 nodotext = "zip"; |
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
220 else |
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
221 nodotext = ext(ext != '.'); |
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
222 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
223 |
19951
8c20fb6caa16
Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
19927
diff
changeset
|
224 if (ispc && strcmp (nodotext, "tar")) |
8c20fb6caa16
Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
19927
diff
changeset
|
225 ## Change file pathname into a mingw style acceptable for tar |
8c20fb6caa16
Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
19927
diff
changeset
|
226 file = __w2mpth__ (file); |
8c20fb6caa16
Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
19927
diff
changeset
|
227 endif |
8c20fb6caa16
Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
19927
diff
changeset
|
228 |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
229 ## Create the output directory if necessary. |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
230 s = stat (dir); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
231 if (isempty (s)) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
232 [status, msg] = mkdir (dir); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
233 if (! status) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
234 error ("unpack: mkdir failed to create %s: %s", dir, msg); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
235 endif |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
236 elseif (! S_ISDIR (s.mode)) |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
237 error ("unpack: %s: not a directory", dir); |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
238 endif |
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
239 |
19234 | 240 if (isfield (commandlist, tolower (nodotext))) |
241 [commandv, commandq, parsefcn, move] = deal (commandlist.(nodotext){:}); | |
242 origdir = pwd (); | |
243 if (move) | |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19579
diff
changeset
|
244 startdir = fileparts (file); |
19234 | 245 else |
246 startdir = origdir; | |
247 endif | |
19951
8c20fb6caa16
Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
19927
diff
changeset
|
248 cstartdir = make_absolute_filename (startdir); |
8c20fb6caa16
Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
19927
diff
changeset
|
249 cenddir = make_absolute_filename (dir); |
20291
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
250 if (cenddir(end) == filesep) |
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
251 cenddir(end) = []; |
2fc43288a6c4
unpack.m: Stop hang when unpacking on to existing filename (bug #45331).
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
252 endif |
27569
29ccef7e5295
New function "is_same_file".
Markus Mützel <markus.muetzel@gmx.de>
parents:
27331
diff
changeset
|
253 needmove = move && ! is_same_file (cstartdir, cenddir); |
6082 | 254 if (nargout > 0 || needmove) |
255 command = commandv; | |
256 else | |
257 command = commandq; | |
258 endif | |
259 else | |
25885
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
260 warning ("unpack: unrecognized FILETYPE <%s>", nodotext); |
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
261 filelist = {}; |
6082 | 262 return; |
263 endif | |
264 | |
24096
8f3db1ac7877
tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents:
23220
diff
changeset
|
265 ## Save and restore the TAR_OPTIONS environment variable used by GNU tar. |
8f3db1ac7877
tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents:
23220
diff
changeset
|
266 tar_options_env = getenv ("TAR_OPTIONS"); |
6082 | 267 unwind_protect |
24096
8f3db1ac7877
tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents:
23220
diff
changeset
|
268 unsetenv ("TAR_OPTIONS"); |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
269 cd (dir); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
270 [status, output] = system (sprintf ([command " 2>&1"], file)); |
6082 | 271 unwind_protect_cleanup |
272 cd (origdir); | |
24096
8f3db1ac7877
tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents:
23220
diff
changeset
|
273 if (! isempty (tar_options_env)) |
8f3db1ac7877
tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents:
23220
diff
changeset
|
274 setenv ("TAR_OPTIONS", tar_options_env); |
8f3db1ac7877
tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents:
23220
diff
changeset
|
275 endif |
6082 | 276 end_unwind_protect |
277 | |
278 if (status) | |
279 error ("unpack: unarchiving program exited with status: %d\n%s", | |
10549 | 280 status, output); |
6082 | 281 endif |
282 | |
6084 | 283 if (nargout > 0 || needmove) |
19927
0cc365dada52
Allow tar, unpack, and zip to run on Windows with CR/NL EOL.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
284 ## Trim the last CR or NL if needed. |
0cc365dada52
Allow tar, unpack, and zip to run on Windows with CR/NL EOL.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
285 files = parsefcn (ostrsplit (output, "\r\n", true))'; |
6082 | 286 |
19234 | 287 ## Move files if necessary. |
6082 | 288 if (needmove) |
19234 | 289 [st, msg] = movefile (files, cenddir); |
6082 | 290 if (! st) |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
291 error ('unpack: unable to move files to "%s": %s', dir, msg); |
6082 | 292 endif |
293 | |
19234 | 294 ## Fix the names of the files since they were moved. |
295 files = strrep (files, cstartdir, cenddir); | |
6082 | 296 endif |
297 | |
298 ## Return output if requested. | |
299 if (nargout > 0) | |
300 filelist = files; | |
301 endif | |
302 endif | |
303 | |
304 endfunction | |
305 | |
306 function files = __parse_zip__ (output) | |
307 ## Parse the output from zip and unzip. | |
308 | |
19234 | 309 ## Skip first line which is Archive header. |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
310 files = char (output(2:end)); |
19234 | 311 ## Trim constant width prefix and return cell array. |
21385
89fa0694aa2e
Fix check-missing-semicolon QA target (bug #47277).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
312 files = cellstr (files(:,14:end)); |
6082 | 313 endfunction |
314 | |
315 function output = __parse_tar__ (output) | |
27331
3bf19af20af8
tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents:
26376
diff
changeset
|
316 ## BSD tar emits file actions in the first 2 columns |
3bf19af20af8
tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents:
26376
diff
changeset
|
317 |
3bf19af20af8
tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents:
26376
diff
changeset
|
318 if (tar_is_bsd ()) |
3bf19af20af8
tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents:
26376
diff
changeset
|
319 output = cellfun (@(x) x(3:end), output, 'UniformOutput', false); |
3bf19af20af8
tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents:
26376
diff
changeset
|
320 endif |
6082 | 321 endfunction |
322 | |
323 function files = __parse_gzip__ (output) | |
324 ## Parse the output from gzip and gunzip returning the files | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21571
diff
changeset
|
325 ## compressed (or decompressed). |
6082 | 326 |
21571
feac06371be1
unpack.m: Use more specific regexp to prevent accidental hits.
Rik <rik@octave.org>
parents:
21385
diff
changeset
|
327 files = regexprep (output, '^.+ -- replaced with (.*)$', '$1'); |
6082 | 328 endfunction |
329 | |
330 function files = __parse_bzip2__ (output) | |
331 ## Parse the output from bzip2 and bunzip2 returning the files | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21571
diff
changeset
|
332 ## compressed (or decompressed). |
6082 | 333 |
20713
2469d78a1d8b
Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents:
20291
diff
changeset
|
334 ## Strip leading blanks and .bz2 extension from filename |
17000
45165d6c4738
unpack.m: Allow zip files to have any suffix (bug #39148)
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
335 files = regexprep (output, '^\s+(.*)\.bz2: .*', '$1'); |
19234 | 336 endfunction |
337 | |
338 | |
22270
2c7acd39e9b7
Conditionally disable tests that rely on optional features
Mike Miller <mtmiller@octave.org>
parents:
21758
diff
changeset
|
339 %!testif HAVE_ZLIB |
24662
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
340 %! envvar = {"TMPDIR", "TMP"}; |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
341 %! envdir = cellfun (@(x) getenv (x), envvar, "uniformoutput", false); |
19234 | 342 %! unwind_protect |
24662
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
343 %! cellfun (@(x) unsetenv (x), envvar); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
344 %! ## Create temporary directory and file for packing and unpacking |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
345 %! dirname = tempname (); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
346 %! assert (mkdir (dirname)); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
347 %! filename = tempname (); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
348 %! fid = fopen (filename, "wt"); |
19259
f8552bd35180
unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents:
19243
diff
changeset
|
349 %! assert (fid >= 0); |
24662
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
350 %! fprintf (fid, "Hello World\n"); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
351 %! fprintf (fid, "123 456 789\n"); |
19259
f8552bd35180
unpack.m: Rewrite BIST test to not produce warning on stderr.
Rik <rik@octave.org>
parents:
19243
diff
changeset
|
352 %! fclose (fid); |
24662
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
353 %! |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
354 %! unwind_protect |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
355 %! copyfile (filename, [filename ".orig"]); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
356 %! gzip (filename, dirname); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
357 %! [~, f] = fileparts (filename); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
358 %! filelist = unpack (fullfile (dirname, [f ".gz"]), tempdir); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
359 %! assert (filelist{1}, filename); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
360 %! fid = fopen ([filename ".orig"], "rb"); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
361 %! assert (fid >= 0); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
362 %! orig_data = fread (fid); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
363 %! fclose (fid); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
364 %! fid = fopen (filename, "rb"); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
365 %! assert (fid >= 0); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
366 %! new_data = fread (fid); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
367 %! fclose (fid); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
368 %! if (orig_data != new_data) |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
369 %! error ("unpack: Unpacked file does not equal original"); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
370 %! endif |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
371 %! unwind_protect_cleanup |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
372 %! unlink (filename); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
373 %! unlink ([filename ".orig"]); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
374 %! confirm_recursive_rmdir (false, "local"); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
375 %! rmdir (dirname, "s"); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
376 %! end_unwind_protect |
19234 | 377 %! unwind_protect_cleanup |
24662
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
378 %! ## Restore environment variables TMPDIR, TMP |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
379 %! for i = 1:numel (envvar) |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
380 %! if (isempty (envdir{i})) |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
381 %! unsetenv (envvar{i}); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
382 %! else |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
383 %! setenv (envvar{i}, envdir{i}); |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
384 %! endif |
276eca875721
Clear environment variables affecting tmpdir before running BIST tests (bug #52627)
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
385 %! endfor |
19234 | 386 %! end_unwind_protect |
387 | |
388 ## Test input validation | |
389 %!error unpack () | |
390 %!error unpack (1,2,3,4) | |
391 %!error <FILE must be a string or cell array of strings> unpack (1) | |
22765
01aae08a0105
maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents:
22760
diff
changeset
|
392 %!error <FILE "_%NOT_A_FILENAME%_" not found> unpack ("_%NOT_A_FILENAME%_") |
01aae08a0105
maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents:
22760
diff
changeset
|
393 %!error <FILE "_%NOT_A_FILENAME%_" not found> unpack ({"_%NOT_A_FILENAME%_"}) |
01aae08a0105
maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents:
22760
diff
changeset
|
394 %!error <FILE "_%NOT_A_FILENAME%_" not found> unpack ({"_%NOT_A_FILENAME%_", "2nd_filename"}) |
25893
96c69234ac98
unpack.m: Fix failing BIST test on Windows (bug #54719).
Rik <rik@octave.org>
parents:
25885
diff
changeset
|
395 %!error <FILETYPE must be a string> |
96c69234ac98
unpack.m: Fix failing BIST test on Windows (bug #54719).
Rik <rik@octave.org>
parents:
25885
diff
changeset
|
396 %! if (isunix || ismac) |
96c69234ac98
unpack.m: Fix failing BIST test on Windows (bug #54719).
Rik <rik@octave.org>
parents:
25885
diff
changeset
|
397 %! unpack ("/", [], 1) |
96c69234ac98
unpack.m: Fix failing BIST test on Windows (bug #54719).
Rik <rik@octave.org>
parents:
25885
diff
changeset
|
398 %! else |
96c69234ac98
unpack.m: Fix failing BIST test on Windows (bug #54719).
Rik <rik@octave.org>
parents:
25885
diff
changeset
|
399 %! unpack ('C:\', [], 1) |
96c69234ac98
unpack.m: Fix failing BIST test on Windows (bug #54719).
Rik <rik@octave.org>
parents:
25885
diff
changeset
|
400 %! endif |
19234 | 401 %!error <FILETYPE must be given for a directory> |
402 %! if (isunix || ismac) | |
403 %! unpack ("/"); | |
404 %! else | |
405 %! unpack ('C:\'); | |
406 %! endif | |
25885
75ed70a1c108
Overhaul unpack and associated functions (bug #54567).
Rik <rik@octave.org>
parents:
25781
diff
changeset
|
407 %!error <FILETYPE must be "gz" for a directory> |
19234 | 408 %! if (isunix || ismac) |
409 %! unpack ("/", [], "foobar"); | |
410 %! else | |
411 %! unpack ('C:\', [], "foobar"); | |
412 %! endif |