|
9 | 9 |
|
10 | 10 | p = ''; |
11 | 11 |
|
12 | | -try |
| 12 | +if ~stdlib.exists(f), return, end |
| 13 | + |
| 14 | +if ~isMATLABReleaseOlderThan('R2025a') |
13 | 15 | v = filePermissions(f); |
14 | | -catch e |
15 | | - switch e.identifier |
16 | | - case "MATLAB:UndefinedFunction", v = file_attributes_legacy(f); |
17 | | - case "Octave:undefined-function" |
18 | | - [s, err] = stat(f); |
19 | | - if err == 0 |
20 | | - p = s.modestr; |
21 | | - end |
22 | | - return |
23 | | - otherwise, rethrow(e) |
| 16 | +elseif stdlib.isoctave() |
| 17 | + [s, err] = stat(f); |
| 18 | + if err == 0 |
| 19 | + p = s.modestr; |
24 | 20 | end |
| 21 | + return |
| 22 | +else |
| 23 | + v = file_attributes_legacy(f); |
25 | 24 | end |
26 | 25 |
|
27 | | -p = perm2char(v); |
| 26 | +p = perm2char(v, f); |
28 | 27 |
|
29 | 28 | end |
30 | 29 |
|
31 | 30 |
|
32 | | -function p = perm2char(v) |
| 31 | +function p = perm2char(v, f) |
| 32 | +arguments |
| 33 | + v (1,1) |
| 34 | + f {mustBeTextScalar} |
| 35 | +end |
| 36 | + |
33 | 37 |
|
34 | 38 | p = '---------'; |
35 | 39 |
|
|
41 | 45 | if v.UserWrite, p(2) = 'w'; end |
42 | 46 | else |
43 | 47 | % cloud / remote locations we don't handle |
44 | | - p = []; |
| 48 | + p = ''; |
45 | 49 | return |
46 | 50 | end |
47 | 51 |
|
| 52 | +if isa(v, "matlab.io.WindowsPermissions") || ispc() |
48 | 53 |
|
49 | | -if isfield(v, 'UserExecute') || isa(v, "matlab.io.UnixPermissions") |
50 | | - if v.UserExecute, p(3) = 'x'; end |
51 | | -elseif ispc() && (isstruct(v) || isa(v, "matlab.io.WindowsPermissions")) |
52 | | - % on Windows, any readable file has executable permission |
53 | | - if p(1) == 'r', p(3) = 'x'; end |
54 | | -end |
| 54 | + if p(1) == 'r' && has_windows_executable_suffix(f) |
| 55 | + p(3) = 'x'; |
| 56 | + end |
55 | 57 |
|
| 58 | + return |
56 | 59 |
|
57 | | -if isstruct(v) || isa(v, "matlab.io.UnixPermissions") |
| 60 | +else |
58 | 61 |
|
59 | | - if v.GroupRead, p(4) = 'r'; end |
60 | | - if v.GroupWrite, p(5) = 'w'; end |
61 | | - if v.GroupExecute, p(6) = 'x'; end |
62 | | - if v.OtherRead, p(7) = 'r'; end |
63 | | - if v.OtherWrite, p(8) = 'w'; end |
64 | | - if v.OtherExecute, p(9) = 'x'; end |
| 62 | + if v.UserExecute, p(3) = 'x'; end |
65 | 63 |
|
66 | 64 | end |
67 | 65 |
|
| 66 | +if v.GroupRead, p(4) = 'r'; end |
| 67 | +if v.GroupWrite, p(5) = 'w'; end |
| 68 | +if v.GroupExecute, p(6) = 'x'; end |
| 69 | +if v.OtherRead, p(7) = 'r'; end |
| 70 | +if v.OtherWrite, p(8) = 'w'; end |
| 71 | +if v.OtherExecute, p(9) = 'x'; end |
| 72 | + |
68 | 73 | end |
69 | 74 |
|
70 | 75 | %!assert(length(get_permissions('get_permissions.m')) >= 9) |
0 commit comments