|
10 | 10 | p = ''; |
11 | 11 |
|
12 | 12 | try |
13 | | - perms = filePermissions(f); |
14 | | - p = perm2char(perms); |
| 13 | + v = filePermissions(f); |
15 | 14 | catch e |
16 | 15 | if ~strcmp(e.identifier, "MATLAB:UndefinedFunction") && ... |
17 | 16 | ~strcmp(e.identifier, "Octave:undefined-function") |
18 | 17 | rethrow(e) |
19 | 18 | end |
20 | 19 |
|
21 | | - [status, v] = fileattrib(f); |
22 | | - if status == 0 |
23 | | - return |
24 | | - end |
25 | | - p = perm2char(v); |
| 20 | + v = file_attributes(f); |
| 21 | + if isempty(v), return, end |
26 | 22 | end |
27 | 23 |
|
| 24 | +p = perm2char(v); |
| 25 | + |
28 | 26 | end |
29 | 27 |
|
30 | 28 |
|
31 | 29 | function p = perm2char(v) |
32 | 30 |
|
33 | 31 | p = '---------'; |
34 | 32 |
|
35 | | -try |
36 | | - % filePermissions object |
| 33 | +if isa(v, "matlab.io.WindowsPermissions") || isa(v, "matlab.io.UnixPermissions") |
37 | 34 | if v.Readable, p(1) = 'r'; end |
38 | 35 | 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 |
44 | | - |
| 36 | +elseif isstruct(v) |
45 | 37 | if v.UserRead, p(1) = 'r'; end |
46 | 38 | if v.UserWrite, p(2) = 'w'; end |
| 39 | +else |
| 40 | + % cloud / remote locations we don't handle |
| 41 | + p = []; |
| 42 | + return |
47 | 43 | end |
48 | 44 |
|
49 | | -% on Windows, any readable file has executable permission |
50 | | -if ispc |
51 | | - if p(1) == 'r' |
52 | | - p(3) = 'x'; |
53 | | - end |
54 | | -else |
| 45 | + |
| 46 | +if isfield(v, 'UserExecute') || isa(v, "matlab.io.UnixPermissions") |
55 | 47 | if v.UserExecute, p(3) = 'x'; end |
| 48 | +elseif ispc && (isstruct(v) || isa(v, "matlab.io.WindowsPermissions")) |
| 49 | + % on Windows, any readable file has executable permission |
| 50 | + if p(1) == 'r', p(3) = 'x'; end |
56 | 51 | end |
57 | 52 |
|
58 | | -% Windows doesn't have these permissions |
59 | 53 |
|
60 | | -try |
| 54 | +if isstruct(v) || isa(v, "matlab.io.UnixPermissions") |
| 55 | + |
61 | 56 | if v.GroupRead, p(4) = 'r'; end |
62 | 57 | if v.GroupWrite, p(5) = 'w'; end |
63 | 58 | if v.GroupExecute, p(6) = 'x'; end |
64 | 59 | if v.OtherRead, p(7) = 'r'; end |
65 | 60 | if v.OtherWrite, p(8) = 'w'; end |
66 | 61 | if v.OtherExecute, p(9) = 'x'; end |
67 | | -catch e |
68 | | - if ~strcmp(e.identifier, "MATLAB:nologicalnan") && ... |
69 | | - ~strcmp(e.identifier, "MATLAB:nonExistentField") && ... |
70 | | - ~strcmp(e.identifier, "MATLAB:noSuchMethodOrField") && ... |
71 | | - ~strcmp(e.message, "invalid conversion from NaN to logical") |
72 | | - rethrow(e) |
73 | | - end |
| 62 | + |
74 | 63 | end |
75 | 64 |
|
76 | 65 | end |
|
0 commit comments