Skip to content

Commit bade30f

Browse files
committed
permissions broad compatibility
1 parent 0c690bf commit bade30f

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

+stdlib/+native/set_permissions.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
function ok = set_permissions(file, readable, writable, executable)
2-
arguments
3-
file (1,1) string
4-
readable (1,1) {mustBeInteger}
5-
writable (1,1) {mustBeInteger}
6-
executable (1,1) {mustBeInteger}
7-
end
2+
3+
mustBeInteger(readable)
4+
mustBeInteger(writable)
5+
mustBeInteger(executable)
86

97
p = filePermissions(file);
108

9+
assert(isscalar(p), "set_permissions: one file only")
10+
1111
k = string.empty;
1212
v = logical.empty;
1313

+stdlib/private/perm2char.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
return
2424
end
2525

26-
if isa(v, "matlab.io.WindowsPermissions") || ispc()
26+
if isa(v, 'matlab.io.WindowsPermissions') || ispc()
2727

2828
if p(1) == 'r'
2929
p(3) = 'x';

example/+javafun/jPosix.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
if isempty(o)
66
s = "";
7-
elseif isa(o, "java.io.File") || isa(o, "java.nio.file.Path") || ...
8-
isa(o, "sun.nio.fs.UnixPath") || isa(o, "sun.nio.fs.WindowsPath")
7+
elseif isa(o, 'java.io.File') || isa(o, 'java.nio.file.Path') || ...
8+
isa(o, 'sun.nio.fs.UnixPath') || isa(o, 'sun.nio.fs.WindowsPath')
99
s = o.toString();
1010
end
1111

test/TestPermissions.m

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ...
2-
TestTags = {'impure'}) ...
1+
classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}) ...
32
TestPermissions < matlab.unittest.TestCase
43

54
properties (TestParameter)
@@ -9,12 +8,12 @@
98

109
methods(TestMethodSetup)
1110
function w_dirs(tc)
12-
tc.applyFixture(matlab.unittest.fixtures.WorkingFolderFixture())
11+
tc.applyFixture(matlab.unittest.fixtures.WorkingFolderFixture());
1312
end
1413
end
1514

1615

17-
methods (Test, TestTags={'R2019b'})
16+
methods (Test, TestTags={'R2017b'})
1817

1918
function test_get_permissions(tc, Ps)
2019
import matlab.unittest.constraints.StartsWithSubstring
@@ -32,20 +31,20 @@ function test_get_permissions(tc, Ps)
3231
end
3332

3433
tc.verifyThat(p, StartsWithSubstring("r"))
35-
if isfile(p) && stdlib.suffix(p) == ".m"
34+
if isfile(p) && strcmp(stdlib.suffix(p), '.m')
3635
tc.verifyEqual(p(3), '-')
3736
end
3837
end
3938
end
4039

4140

4241
function test_get_permissions_exe(tc)
43-
matlab_exe = fullfile(matlabroot, "bin/matlab");
42+
matlab_exe = [matlabroot, '/bin/matlab'];
4443
if ispc()
45-
matlab_exe = matlab_exe + ".exe";
44+
matlab_exe = [matlab_exe, '.exe'];
4645
end
4746

48-
tc.assertThat(matlab_exe, matlab.unittest.constraints.IsFile)
47+
tc.assertTrue(isfile(matlab_exe))
4948
p = stdlib.get_permissions(matlab_exe);
5049

5150
tc.assertNotEmpty(p)
@@ -57,7 +56,7 @@ function test_get_permissions_exe(tc)
5756
function test_set_permissions_nowrite(tc)
5857
import matlab.unittest.constraints.StartsWithSubstring
5958

60-
nw = fullfile(pwd(), "no-write");
59+
nw = [pwd(), '/no-write'];
6160

6261
tc.assertTrue(stdlib.touch(nw))
6362
r = stdlib.set_permissions(nw, 0, -1, 0);
@@ -72,7 +71,7 @@ function test_set_permissions_nowrite(tc)
7271
tc.assertEqual(b, 'native')
7372
end
7473

75-
if ~ispc() || b ~= "legacy"
74+
if ~ispc() || ~strcmp(b, 'legacy')
7675
tc.verifyThat(p, StartsWithSubstring("r-"), "no-write permission failed to set")
7776
end
7877

@@ -90,7 +89,7 @@ function test_set_permissions_noread(tc)
9089
% fileattrib can not even set the permissions on Linux.
9190
tc.assumeFalse(stdlib.matlabOlderThan('R2025a'))
9291

93-
nr = fullfile(pwd(), "no-read");
92+
nr = [pwd(), '/no-read'];
9493

9594
tc.assertTrue(stdlib.touch(nr))
9695
tc.assertTrue(stdlib.set_permissions(nr, -1, 0, 0))

0 commit comments

Comments
 (0)