|
9 | 9 |
|
10 | 10 | p = ''; |
11 | 11 |
|
12 | | -if ~stdlib.isoctave() && ~stdlib.too_old('R2025a') |
| 12 | +try |
13 | 13 | perms = filePermissions(f); |
14 | 14 | p = perm2char(perms); |
15 | | -% elseif ~ispc && ~isMATLABReleaseOlderThan('R2024b') |
16 | | -% % undocumented internals in Matlab R2024b, does not work on Windows |
17 | | -% perms = matlab.io.UnixPermissions(f); |
18 | | -% p = perm2str(perms); |
19 | | -else |
| 15 | +catch e |
| 16 | + if ~strcmp(e.identifier, "MATLAB:UndefinedFunction") && ... |
| 17 | + ~strcmp(e.identifier, "Octave:undefined-function") |
| 18 | + rethrow(e) |
| 19 | + end |
| 20 | + |
20 | 21 | [status, v] = fileattrib(f); |
21 | 22 | if status == 0 |
22 | 23 | return |
|
31 | 32 |
|
32 | 33 | p = '---------'; |
33 | 34 |
|
34 | | -groupRead = ~isnan(v.GroupRead) && logical(v.GroupRead); |
35 | | -groupWrite = ~isnan(v.GroupWrite) && logical(v.GroupWrite); |
36 | | -groupExecute = ~isnan(v.GroupExecute) && logical(v.GroupExecute); |
37 | | -otherRead = ~isnan(v.OtherRead) && logical(v.OtherRead); |
38 | | -otherWrite = ~isnan(v.OtherWrite) && logical(v.OtherWrite); |
39 | | -otherExecute = ~isnan(v.OtherExecute) && logical(v.OtherExecute); |
| 35 | +try |
| 36 | + % filePermissions object |
| 37 | + if v.Readable, p(1) = 'r'; end |
| 38 | + if v.Writable, p(2) = 'w'; end |
| 39 | +catch e |
| 40 | + if ~strcmp(e.identifier, "MATLAB:nonExistentField") && ... |
| 41 | + ~strcmp(e.identifier, "Octave:invalid-indexing") |
| 42 | + rethrow(e) |
| 43 | + end |
40 | 44 |
|
41 | | -if isstruct(v) % from fileattrib |
42 | 45 | if v.UserRead, p(1) = 'r'; end |
43 | 46 | if v.UserWrite, p(2) = 'w'; end |
44 | | -else % filePermissions object |
45 | | - if v.Readable, p(1) = 'r'; end |
46 | | - if v.Writable, p(2) = 'w'; end |
47 | 47 | end |
48 | 48 |
|
49 | 49 | if v.UserExecute, p(3) = 'x'; end |
50 | | -if groupRead, p(4) = 'r'; end |
51 | | -if groupWrite, p(5) = 'w'; end |
52 | | -if groupExecute, p(6) = 'x'; end |
53 | | -if otherRead, p(7) = 'r'; end |
54 | | -if otherWrite, p(8) = 'w'; end |
55 | | -if otherExecute, p(9) = 'x'; end |
| 50 | + |
| 51 | +try |
| 52 | + if v.GroupRead, p(4) = 'r'; end |
| 53 | + if v.GroupWrite, p(5) = 'w'; end |
| 54 | + if v.GroupExecute, p(6) = 'x'; end |
| 55 | + if v.OtherRead, p(7) = 'r'; end |
| 56 | + if v.OtherWrite, p(8) = 'w'; end |
| 57 | + if v.OtherExecute, p(9) = 'x'; end |
| 58 | +catch e |
| 59 | + if ~strcmp(e.identifier, "MATLAB:nologicalnan") && ... |
| 60 | + ~strcmp(e.identifier, "MATLAB:nonExistentField") && ... |
| 61 | + ~strcmp(e.message, "invalid conversion from NaN to logical") |
| 62 | + rethrow(e) |
| 63 | + end |
| 64 | +end |
56 | 65 |
|
57 | 66 | end |
58 | 67 |
|
|
0 commit comments