Mercurial > octave
annotate scripts/miscellaneous/dir.m @ 27241:733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
* dir.m: Don't enter main body of code if stat() call fails and number of files
(nf) is 0. Use new variable cnt to place entries in to pre-declared info array.
If lstat call fails on file, skip further processing and "continue" with for
loop. At end of for loop over all files, delete any unused elements from info
array.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 12 Jul 2019 09:11:58 -0700 |
parents | 12fe42e16841 |
children | d5e24466835f |
rev | line source |
---|---|
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
1 ## Copyright (C) 2004-2019 John W. Eaton |
4694 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23396
diff
changeset
|
5 ## Octave is free software: you can redistribute it and/or modify it |
4694 | 6 ## 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:
23396
diff
changeset
|
7 ## 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
|
8 ## (at your option) any later version. |
4694 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## GNU General Public License for more details. |
4694 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## 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:
23396
diff
changeset
|
17 ## <https://www.gnu.org/licenses/>. |
4694 | 18 |
19 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
20 ## @deftypefn {} {} dir |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
21 ## @deftypefnx {} {} dir (@var{directory}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
22 ## @deftypefnx {} {[@var{list}] =} dir (@var{directory}) |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
23 ## Display file listing for directory @var{directory}. |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
24 ## |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
25 ## If @var{directory} is not specified then list the present working directory. |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
26 ## |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
27 ## If a return value is requested, return a structure array with the fields |
4694 | 28 ## |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
29 ## @table @asis |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
30 ## @item name |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17908
diff
changeset
|
31 ## File or directory name. |
17513
fedcd3717ebc
doc: grammarcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents:
17397
diff
changeset
|
32 ## |
23265
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
33 ## @item folder |
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
34 ## Location of file or directory |
23396
945b53af4655
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
23268
diff
changeset
|
35 ## |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
36 ## @item date |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
37 ## Timestamp of file modification (string value). |
17513
fedcd3717ebc
doc: grammarcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents:
17397
diff
changeset
|
38 ## |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
39 ## @item bytes |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
40 ## File size in bytes. |
17513
fedcd3717ebc
doc: grammarcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents:
17397
diff
changeset
|
41 ## |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
42 ## @item isdir |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17908
diff
changeset
|
43 ## True if name is a directory. |
17513
fedcd3717ebc
doc: grammarcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents:
17397
diff
changeset
|
44 ## |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
45 ## @item datenum |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
46 ## Timestamp of file modification as serial date number (double). |
17513
fedcd3717ebc
doc: grammarcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents:
17397
diff
changeset
|
47 ## |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
48 ## @item statinfo |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
49 ## Information structure returned from @code{stat}. |
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
50 ## @end table |
4694 | 51 ## |
17397
0bf2fc8562c9
doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
52 ## If @var{directory} is a filename, rather than a directory, then return |
17908
7df8f5372ea8
doc: Add note about wildcard expansion in ls and dir functions (bug #40544).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
53 ## information about the named file. @var{directory} may also be a list rather |
7df8f5372ea8
doc: Add note about wildcard expansion in ls and dir functions (bug #40544).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
54 ## than a single directory or file. |
7df8f5372ea8
doc: Add note about wildcard expansion in ls and dir functions (bug #40544).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
55 ## |
7df8f5372ea8
doc: Add note about wildcard expansion in ls and dir functions (bug #40544).
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
56 ## @var{directory} is subject to shell expansion if it contains any wildcard |
19198 | 57 ## characters @samp{*}, @samp{?}, @samp{[]}. To find a literal example of a |
58 ## wildcard character the wildcard must be escaped using the backslash operator | |
59 ## @samp{\}. | |
6955 | 60 ## |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
61 ## Note that for symbolic links, @code{dir} returns information about the |
20181
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
62 ## file that the symbolic link points to rather than the link itself. |
7007 | 63 ## However, if the link points to a nonexistent file, @code{dir} returns |
6955 | 64 ## information about the link. |
19198 | 65 ## @seealso{ls, readdir, glob, what, stat, lstat} |
4694 | 66 ## @end deftypefn |
67 | |
68 ## Author: jwe | |
69 | |
19198 | 70 ## FIXME: This is quite slow for large directories. |
71 ## Perhaps it should be converted to C++? | |
4694 | 72 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
73 function retval = dir (directory) |
4694 | 74 |
5689 | 75 if (nargin == 0) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
76 directory = "."; |
5689 | 77 elseif (nargin > 1) |
6046 | 78 print_usage (); |
4694 | 79 endif |
80 | |
19198 | 81 if (! ischar (directory)) |
82 error ("dir: DIRECTORY argument must be a string"); | |
83 endif | |
84 | |
5690 | 85 ## Prep the retval. |
6947 | 86 info = struct (zeros (0, 1), |
23265
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
87 {"name", "folder" "date", "bytes", "isdir", "datenum", "statinfo"}); |
5689 | 88 |
19198 | 89 if (strcmp (directory, "*")) |
90 directory = "."; | |
91 endif | |
92 if (strcmp (directory, ".")) | |
93 flst = {"."}; | |
94 nf = 1; | |
95 else | |
22155
289409b2992d
Allow dir to accept [ and ] in arguments. (bug #47950)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21634
diff
changeset
|
96 flst = __wglob__ (directory); |
19198 | 97 nf = numel (flst); |
98 endif | |
5689 | 99 |
19198 | 100 ## Determine the file list for the case where a single directory is specified. |
101 if (nf == 1) | |
102 fn = flst{1}; | |
103 [st, err, msg] = stat (fn); | |
104 if (err < 0) | |
105 warning ("dir: 'stat (%s)' failed: %s", fn, msg); | |
106 nf = 0; | |
107 elseif (S_ISDIR (st.mode)) | |
108 flst = readdir (flst{1}); | |
109 nf = numel (flst); | |
23248
529c6d0c6684
dir.m: Improve performance by 2.3X (bug #50416).
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
110 flst = strcat ([fn filesep], flst); |
5690 | 111 endif |
19198 | 112 endif |
5689 | 113 |
27241
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
114 if (nf > 0) |
23248
529c6d0c6684
dir.m: Improve performance by 2.3X (bug #50416).
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
115 |
23256
99ee4dd83ceb
dir.m: Fix regression in 529c6d0c6684.
Rik <rik@octave.org>
parents:
23249
diff
changeset
|
116 fs = regexptranslate ("escape", filesep ("all")); |
23268
efb139519388
dir.m: Do not include trailing filesep in "folder". Fix BIST. (bug #50504).
Markus Mützel <markus.muetzel@gmx.de>
parents:
23265
diff
changeset
|
117 re = sprintf ('(^.+)[%s]([^%s.]*)([.][^%s]*)?$', fs, fs, fs); |
23265
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
118 last_dir = last_absdir = ""; |
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
119 info(nf,1).name = ""; # pre-declare size of struct array |
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
120 |
19198 | 121 ## Collect results. |
27241
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
122 cnt = 0; |
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
123 for i = 1:nf |
19198 | 124 fn = flst{i}; |
125 [st, err, msg] = lstat (fn); | |
126 if (err < 0) | |
127 warning ("dir: 'lstat (%s)' failed: %s", fn, msg); | |
27241
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
128 continue; |
19198 | 129 else |
130 ## If we are looking at a link that points to something, | |
131 ## return info about the target of the link, otherwise, return | |
132 ## info about the link itself. | |
133 if (S_ISLNK (st.mode)) | |
23265
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
134 [xst, err] = stat (fn); |
19198 | 135 if (! err) |
136 st = xst; | |
137 endif | |
138 endif | |
23265
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
139 tmpdir = regexprep (fn, re, '$1'); |
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
140 fn = regexprep (fn, re, '$2$3'); |
27241
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
141 info(++cnt).name = fn; |
23265
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
142 if (! strcmp (last_dir, tmpdir)) |
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
143 ## Caching mechanism to speed up function |
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
144 last_dir = tmpdir; |
23268
efb139519388
dir.m: Do not include trailing filesep in "folder". Fix BIST. (bug #50504).
Markus Mützel <markus.muetzel@gmx.de>
parents:
23265
diff
changeset
|
145 last_absdir = canonicalize_file_name (last_dir); |
23265
44d51b2b691c
dir.m: Add folder entry to output struct for Matlab compatibility (bug #50504).
Rik <rik@octave.org>
parents:
23256
diff
changeset
|
146 endif |
27241
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
147 info(cnt).folder = last_absdir; |
19198 | 148 lt = localtime (st.mtime); |
27241
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
149 info(cnt).date = strftime ("%d-%b-%Y %T", lt); |
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
150 info(cnt).bytes = st.size; |
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
151 info(cnt).isdir = S_ISDIR (st.mode); |
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
152 info(cnt).datenum = [lt.year + 1900, lt.mon + 1, lt.mday, ... |
23249
21fc54e4bb7b
dir.m: Improve performance by another 2X (bug #50416).
Rik <rik@octave.org>
parents:
23248
diff
changeset
|
153 lt.hour, lt.min, lt.sec]; |
27241
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
154 info(cnt).statinfo = st; |
19198 | 155 endif |
156 endfor | |
27241
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
157 info((cnt+1):end) = []; # remove any unused entries |
23249
21fc54e4bb7b
dir.m: Improve performance by another 2X (bug #50416).
Rik <rik@octave.org>
parents:
23248
diff
changeset
|
158 ## A lot of gymnastics in order to call datenum just once. 2x speed up. |
21fc54e4bb7b
dir.m: Improve performance by another 2X (bug #50416).
Rik <rik@octave.org>
parents:
23248
diff
changeset
|
159 dvec = [info.datenum]([[1:6:end]', [2:6:end]', [3:6:end]', ... |
21fc54e4bb7b
dir.m: Improve performance by another 2X (bug #50416).
Rik <rik@octave.org>
parents:
23248
diff
changeset
|
160 [4:6:end]', [5:6:end]', [6:6:end]']); |
21fc54e4bb7b
dir.m: Improve performance by another 2X (bug #50416).
Rik <rik@octave.org>
parents:
23248
diff
changeset
|
161 dnum = datenum (dvec); |
27241
733431da9742
dir.m: Gracefully handle race conditions when file is deleted (bug #56618).
Rik <rik@octave.org>
parents:
26763
diff
changeset
|
162 ctmp = mat2cell (dnum, ones (cnt,1), 1); |
23249
21fc54e4bb7b
dir.m: Improve performance by another 2X (bug #50416).
Rik <rik@octave.org>
parents:
23248
diff
changeset
|
163 [info.datenum] = ctmp{:}; |
5689 | 164 endif |
165 | |
5690 | 166 ## Return the output arguments. |
5689 | 167 if (nargout > 0) |
5690 | 168 ## Return the requested structure. |
5689 | 169 retval = info; |
19198 | 170 elseif (numel (info) > 0) |
5690 | 171 ## Print the structure to the screen. |
21634
96518f623c91
Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents:
21633
diff
changeset
|
172 printf ("%s", list_in_columns ({info.name})); |
5689 | 173 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14327
diff
changeset
|
174 warning ("dir: nonexistent directory '%s'", directory); |
5689 | 175 endif |
176 | |
4694 | 177 endfunction |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
178 |
19198 | 179 |
180 %!test | |
26763
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
181 %! orig_dir = pwd (); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
182 %! tmp_dir = tempname (); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
183 %! unwind_protect |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
184 %! assert (mkdir (tmp_dir)); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
185 %! chdir (tmp_dir); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
186 %! fclose (fopen ("f1", "w")); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
187 %! list = dir (); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
188 %! assert (isstruct (list) && ! isempty (list)); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
189 %! assert (fieldnames (list), |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
190 %! {"name"; "folder"; "date"; "bytes"; "isdir"; "datenum"; "statinfo"}); |
19198 | 191 %! |
26763
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
192 %! if (isunix ()) |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
193 %! idx = find (strcmp ({list.name}, "."), 1); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
194 %! assert ({list(idx:idx+1).name}, {".", ".."}); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
195 %! assert ([list(idx:idx+1).isdir], [true true]); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
196 %! endif |
19198 | 197 %! |
26763
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
198 %! ## test that specifying a filename works the same as using a directory. |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
199 %! found = find (! [list.isdir], 1); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
200 %! if (! isempty (found)) |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
201 %! list2 = dir (fullfile (list(found).folder, list(found).name)); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
202 %! assert (list(found), list2); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
203 %! endif |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
204 %! unwind_protect_cleanup |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
205 %! chdir (orig_dir); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
206 %! confirm_recursive_rmdir (false, "local"); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
207 %! if (exist (tmp_dir)) |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
208 %! rmdir (tmp_dir, "s"); |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
209 %! endif |
12fe42e16841
use temporary directory for testing dir function
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
210 %! end_unwind_protect |
19198 | 211 |
212 ## Test input validation | |
213 %!error <DIRECTORY argument must be a string> dir (1) | |
214 %!warning <nonexistent directory> dir ("_%UNLIKELY_DIR_NAME%_"); |