Skip to content

Commit 9755b0a

Browse files
committed
canonical: avoid use of deprecated fileattrib
If modern alternative available is_*: no fileattrib in R2025a+ f
1 parent b0d6851 commit 9755b0a

File tree

5 files changed

+74
-30
lines changed

5 files changed

+74
-30
lines changed

+stdlib/canonical.m

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,34 @@
1717
strict = false;
1818
end
1919

20-
[s, r] = fileAttribCompatible(file);
20+
c = '';
2121

22-
if s == 1
23-
c = r.Name;
24-
elseif ~strict && ~stdlib.strempty(r)
25-
c = stdlib.normalize(file);
26-
else
27-
c = '';
28-
end
22+
try
23+
p = filePermissions(file);
24+
c = p.AbsolutePath;
25+
if ischar(file)
26+
c = char(c);
27+
end
28+
catch e
29+
switch e.identifier
30+
case 'MATLAB:io:filesystem:filePermissions:CannotFindLocation'
31+
if ~strict && ~stdlib.strempty(file)
32+
c = stdlib.normalize(file);
33+
end
34+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
35+
[s, r] = fileAttribCompatible(file);
36+
if s == 1
37+
c = r.Name;
38+
elseif ~strict && ~stdlib.strempty(r)
39+
c = stdlib.normalize(file);
40+
end
41+
otherwise
42+
rethrow(e)
43+
end
2944

30-
if isstring(file)
31-
c = string(c);
45+
if isstring(file)
46+
c = string(c);
47+
end
3248
end
3349

3450
end

+stdlib/is_exe.m

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,26 @@
1616
return
1717
end
1818

19-
a = file_attributes(file);
2019

21-
if ~isempty(a)
22-
y = ~a.directory && (a.UserExecute || a.GroupExecute || a.OtherExecute);
20+
try
21+
a = filePermissions(file);
22+
if a.Type == matlab.io.FileSystemEntryType.File
23+
if ispc
24+
y = a.Readable;
25+
else
26+
y = a.UserExecute || a.GroupExecute || a.OtherExecute;
27+
end
28+
end
29+
catch e
30+
switch e.identifier
31+
case 'MATLAB:io:filesystem:filePermissions:CannotFindLocation'
32+
y = false;
33+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
34+
a = file_attributes(file);
35+
y = ~isempty(a) && ~a.directory && (a.UserExecute || a.GroupExecute || a.OtherExecute);
36+
otherwise
37+
rethrow(e)
38+
end
2339
end
2440

2541
end
@@ -28,4 +44,4 @@
2844
%! if isunix()
2945
%! assert(stdlib.is_exe([matlabroot, '/bin/octave']))
3046
%! end
31-
%!assert (~stdlib.is_exe('.'))
47+
%!assert (~stdlib.is_exe('.'))

+stdlib/is_readable.m

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@
99

1010
function y = is_readable(file)
1111

12-
a = file_attributes(file);
13-
14-
if isempty(a)
15-
y = false;
16-
else
17-
y = a.UserRead || a.GroupRead || a.OtherRead;
12+
try
13+
a = filePermissions(file);
14+
y = a.Readable;
15+
catch e
16+
switch e.identifier
17+
case 'MATLAB:io:filesystem:filePermissions:CannotFindLocation'
18+
y = false;
19+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
20+
a = file_attributes(file);
21+
y = ~isempty(a) && (a.UserRead || a.GroupRead || a.OtherRead);
22+
otherwise
23+
rethrow(e)
24+
end
1825
end
1926

2027
end
2128

22-
%!assert (stdlib.is_readable('.'))
29+
%!assert (stdlib.is_readable('.'))

+stdlib/is_writable.m

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@
99

1010
function y = is_writable(file)
1111

12-
a = file_attributes(file);
13-
14-
if isempty(a)
15-
y = false;
16-
else
17-
y = a.UserWrite || a.GroupWrite || a.OtherWrite;
12+
try
13+
a = filePermissions(file);
14+
y = a.Writable;
15+
catch e
16+
switch e.identifier
17+
case 'MATLAB:io:filesystem:filePermissions:CannotFindLocation'
18+
y = false;
19+
case {'MATLAB:UndefinedFunction', 'Octave:undefined-function'}
20+
a = file_attributes(file);
21+
y = ~isempty(a) && (a.UserWrite || a.GroupWrite || a.OtherWrite);
22+
otherwise
23+
rethrow(e)
24+
end
1825
end
1926

2027
end
2128

22-
%!assert (islogical(stdlib.is_writable('.')))
29+
%!assert (islogical(stdlib.is_writable('.')))

matlab-stdlib.prj

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)