annotate scripts/miscellaneous/tar.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 7854d5752dd2
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2005-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27331
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 ##
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents: 5808
diff changeset
8 ## This file is part of Octave.
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents: 5808
diff changeset
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
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents: 5808
diff changeset
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: 22323
diff changeset
13 ## (at your option) any later version.
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents: 5808
diff changeset
14 ##
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents: 5808
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents: 5808
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
6049
04c2ad6d1679 [project @ 2006-10-13 14:32:15 by jwe]
jwe
parents: 5808
diff changeset
19 ##
5807
29c4fb42b210 [project @ 2006-05-11 01:48:56 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6049
diff changeset
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 ########################################################################
5807
29c4fb42b210 [project @ 2006-05-11 01:48:56 by jwe]
jwe
parents:
diff changeset
25
29c4fb42b210 [project @ 2006-05-11 01:48:56 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20164
diff changeset
27 ## @deftypefn {} {@var{filelist} =} tar (@var{tarfile}, @var{files})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20164
diff changeset
28 ## @deftypefnx {} {@var{filelist} =} tar (@var{tarfile}, @var{files}, @var{rootdir})
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
29 ## Pack the list of files and directories specified in @var{files} into the
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
30 ## TAR archive @var{tarfile}.
5808
a18d85bdff31 [project @ 2006-05-11 03:11:03 by jwe]
jwe
parents: 5807
diff changeset
31 ##
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19951
diff changeset
32 ## @var{files} is a character array or cell array of strings. Shell wildcards
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19951
diff changeset
33 ## in the filename such as @samp{*} or @samp{?} are accepted and expanded.
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19951
diff changeset
34 ## Directories are recursively traversed and all files are added to the
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19951
diff changeset
35 ## archive.
5807
29c4fb42b210 [project @ 2006-05-11 01:48:56 by jwe]
jwe
parents:
diff changeset
36 ##
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
37 ## If @var{rootdir} is defined then any files without absolute pathnames are
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
38 ## located relative to @var{rootdir} rather than the current directory.
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
39 ##
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
40 ## The optional output @var{filelist} is a list of the files that were included
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
41 ## in the archive.
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
42 ## @seealso{untar, unpack, bzip2, gzip, zip}
5807
29c4fb42b210 [project @ 2006-05-11 01:48:56 by jwe]
jwe
parents:
diff changeset
43 ## @end deftypefn
29c4fb42b210 [project @ 2006-05-11 01:48:56 by jwe]
jwe
parents:
diff changeset
44
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
45 function filelist = tar (tarfile, files, rootdir = ".")
5808
a18d85bdff31 [project @ 2006-05-11 03:11:03 by jwe]
jwe
parents: 5807
diff changeset
46
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 28087
diff changeset
47 if (nargin < 2)
12500
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
48 print_usage ();
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
49 endif
5807
29c4fb42b210 [project @ 2006-05-11 01:48:56 by jwe]
jwe
parents:
diff changeset
50
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
51 if (! ischar (tarfile))
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
52 error ("tar: TARFILE must be a string");
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
53 elseif (ischar (files))
12500
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
54 files = cellstr (files);
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
55 elseif (! iscellstr (files))
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
56 error ("tar: FILES must be a character array or cellstr");
12500
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
57 endif
5807
29c4fb42b210 [project @ 2006-05-11 01:48:56 by jwe]
jwe
parents:
diff changeset
58
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
59 rootdir = tilde_expand (rootdir);
5808
a18d85bdff31 [project @ 2006-05-11 03:11:03 by jwe]
jwe
parents: 5807
diff changeset
60
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
61 tarfile = make_absolute_filename (tarfile);
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19535
diff changeset
62
19951
8c20fb6caa16 Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19927
diff changeset
63 if (ispc)
8c20fb6caa16 Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19927
diff changeset
64 ## Change tarfile 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
65 tarfile = __w2mpth__ (tarfile);
8c20fb6caa16 Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19927
diff changeset
66 endif
8c20fb6caa16 Fix XFAIL with tar and unpack tests (bug #44007, bug #43979).
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 19927
diff changeset
67
27331
3bf19af20af8 tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents: 26376
diff changeset
68 ## BSD tar emits progress on stderr
3bf19af20af8 tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents: 26376
diff changeset
69 if (tar_is_bsd ())
3bf19af20af8 tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents: 26376
diff changeset
70 cmd = sprintf ("tar cvf %s -C %s %s 2>&1",
3bf19af20af8 tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents: 26376
diff changeset
71 tarfile, rootdir, sprintf (" '%s'", files{:}));
3bf19af20af8 tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents: 26376
diff changeset
72 else
3bf19af20af8 tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents: 26376
diff changeset
73 cmd = sprintf ("tar cvf %s -C %s %s",
3bf19af20af8 tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents: 26376
diff changeset
74 tarfile, rootdir, sprintf (" %s", files{:}));
28947
b73a54c31152 maint: Use Octave-specific end keywords rather than just 'end'.
Rik <rik@octave.org>
parents: 28892
diff changeset
75 endif
12500
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
76
24096
8f3db1ac7877 tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents: 23220
diff changeset
77 ## 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
78 tar_options_env = getenv ("TAR_OPTIONS");
8f3db1ac7877 tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents: 23220
diff changeset
79 unwind_protect
8f3db1ac7877 tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents: 23220
diff changeset
80 unsetenv ("TAR_OPTIONS");
8f3db1ac7877 tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents: 23220
diff changeset
81 [status, output] = system (cmd);
8f3db1ac7877 tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents: 23220
diff changeset
82 unwind_protect_cleanup
8f3db1ac7877 tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents: 23220
diff changeset
83 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
84 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
85 endif
8f3db1ac7877 tar, untar, unpack: ensure TAR_OPTIONS doesn't affect behavior (bug #52095)
Mike Miller <mtmiller@octave.org>
parents: 23220
diff changeset
86 end_unwind_protect
5807
29c4fb42b210 [project @ 2006-05-11 01:48:56 by jwe]
jwe
parents:
diff changeset
87
12500
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
88 if (status)
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
89 error ("tar: tar exited with status = %d", status);
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
90 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
91
12500
8f2056646dba Improve docstrings for archive functions (gzip, bzip2, etc.)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
92 if (nargout > 0)
19927
0cc365dada52 Allow tar, unpack, and zip to run on Windows with CR/NL EOL.
Rik <rik@octave.org>
parents: 19925
diff changeset
93 filelist = ostrsplit (output, "\r\n", true);
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
94 filelist = filelist';
27331
3bf19af20af8 tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents: 26376
diff changeset
95
3bf19af20af8 tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents: 26376
diff changeset
96 ## 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
97 if (tar_is_bsd ())
3bf19af20af8 tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents: 26376
diff changeset
98 filelist = cellfun (@(x) x(3:end), filelist, 'UniformOutput', false);
3bf19af20af8 tar, untar, unpack: Add support for BSD tar (bug #53695)
Andrew Janke <andrew@apjanke.net>
parents: 26376
diff changeset
99 endif
5808
a18d85bdff31 [project @ 2006-05-11 03:11:03 by jwe]
jwe
parents: 5807
diff changeset
100 endif
a18d85bdff31 [project @ 2006-05-11 03:11:03 by jwe]
jwe
parents: 5807
diff changeset
101
5807
29c4fb42b210 [project @ 2006-05-11 01:48:56 by jwe]
jwe
parents:
diff changeset
102 endfunction
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 17243
diff changeset
103
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
104
25231
e1024058833c test: change remaining %!xtests into %!tests
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
105 ## FIXME: This test may fail if the tar command is not installed. If this
e1024058833c test: change remaining %!xtests into %!tests
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
106 ## test fails, it might be better to change it into a testif with a
e1024058833c test: change remaining %!xtests into %!tests
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
107 ## runtime condition on the tar program.
e1024058833c test: change remaining %!xtests into %!tests
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
108 %!test
19925
ee7159d9a330 tar.m: Re-code BIST test restore working directory even when test fails (bug #44007).
Rik <rik@octave.org>
parents: 19697
diff changeset
109 %! ## test tar together with untar
19535
827cc33ae05c avoid warning message in test for tar function
John W. Eaton <jwe@octave.org>
parents: 19258
diff changeset
110 %! orig_dir = pwd ();
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
111 %! unwind_protect
19925
ee7159d9a330 tar.m: Re-code BIST test restore working directory even when test fails (bug #44007).
Rik <rik@octave.org>
parents: 19697
diff changeset
112 %! dirname = tarname = outdir = "";
ee7159d9a330 tar.m: Re-code BIST test restore working directory even when test fails (bug #44007).
Rik <rik@octave.org>
parents: 19697
diff changeset
113 %! dirname = tempname ();
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
114 %! assert (mkdir (dirname));
19535
827cc33ae05c avoid warning message in test for tar function
John W. Eaton <jwe@octave.org>
parents: 19258
diff changeset
115 %! chdir (dirname);
827cc33ae05c avoid warning message in test for tar function
John W. Eaton <jwe@octave.org>
parents: 19258
diff changeset
116 %! dirname2 = "dir2";
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
117 %! assert (mkdir (dirname2));
19925
ee7159d9a330 tar.m: Re-code BIST test restore working directory even when test fails (bug #44007).
Rik <rik@octave.org>
parents: 19697
diff changeset
118 %! fname1 = "file1";
ee7159d9a330 tar.m: Re-code BIST test restore working directory even when test fails (bug #44007).
Rik <rik@octave.org>
parents: 19697
diff changeset
119 %! fname2 = fullfile (dirname2, "file2");
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
120 %! fid = fopen (fname1, "wt");
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
121 %! assert (fid >= 0);
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
122 %! fdisp (fid, "Hello World");
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19535
diff changeset
123 %! fclose (fid);
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
124 %! fid = fopen (fname2, "wt");
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
125 %! assert (fid >= 0);
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
126 %! fdisp (fid, "Goodbye World");
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19535
diff changeset
127 %! fclose (fid);
19925
ee7159d9a330 tar.m: Re-code BIST test restore working directory even when test fails (bug #44007).
Rik <rik@octave.org>
parents: 19697
diff changeset
128 %! tarname = [tempname() ".tar"];
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
129 %! filelist = tar (tarname, {dirname2, fname1});
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
130 %! if (! strcmp (filelist{3}, fname1))
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
131 %! error ("tar file contents does not match expected file");
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
132 %! endif
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
133 %! if (! exist (tarname, "file"))
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
134 %! error ("tar archive file cannot be found!");
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
135 %! endif
28892
3cac3ceb9629 maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents: 28886
diff changeset
136 %! outdir = tempname ();
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
137 %! untar (tarname, outdir);
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
138 %! fid = fopen (fullfile (outdir, fname1), "rt");
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
139 %! assert (fid >= 0);
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
140 %! str = fgetl (fid);
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
141 %! fclose (fid);
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
142 %! assert (str, "Hello World");
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
143 %! fid = fopen (fullfile (outdir, fname2), "rt");
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
144 %! assert (fid >= 0);
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
145 %! str = fgetl (fid);
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
146 %! fclose (fid);
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
147 %! assert (str, "Goodbye World");
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
148 %! unwind_protect_cleanup
19925
ee7159d9a330 tar.m: Re-code BIST test restore working directory even when test fails (bug #44007).
Rik <rik@octave.org>
parents: 19697
diff changeset
149 %! chdir (orig_dir);
19927
0cc365dada52 Allow tar, unpack, and zip to run on Windows with CR/NL EOL.
Rik <rik@octave.org>
parents: 19925
diff changeset
150 %! unlink (tarname);
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
151 %! confirm_recursive_rmdir (false, "local");
28087
9cb04a9e81ec rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents: 27978
diff changeset
152 %! sts = rmdir (dirname, "s");
9cb04a9e81ec rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents: 27978
diff changeset
153 %! sts = rmdir (outdir, "s");
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
154 %! end_unwind_protect
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
155
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
156 ## Test input validation
28886
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
157 %!error <Invalid call> tar ()
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
158 %!error <Invalid call> tar (1)
19258
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
159 %!error <TARFILE must be a string> tar (1, "foobar")
a4e993343e93 Overhaul the archive family (bzip2, gzip, zip, tar) of m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
160 %!error <FILES must be a character array or cellstr> tar ("foobar", 1)