Skip to content

Commit d21100e

Browse files
committed
set_modtime shell fallback
1 parent ea3303d commit d21100e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

+stdlib/set_modtime.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@
2424
ok = stdlib.python.set_modtime(p, utc);
2525
end
2626

27+
if ok, return, end
28+
29+
if ispc()
30+
cmd = sprintf('pwsh -Command "(Get-Item ''%s'').LastWriteTime = ''%s''"', p, string(t, "yyyy-MM-dd HH:mm:ss"));
31+
elseif ismac()
32+
cmd = sprintf("touch -mt %s %s", string(t, "yyyyMMddHHmm"), p);
33+
else
34+
cmd = sprintf("touch -d '%s' %s", string(t, "yyyy-MM-dd HH:mm:ss"), p);
35+
end
36+
37+
[s, m] = system(cmd);
38+
ok = s == 0;
39+
40+
if ~ok
41+
warning("stdlib:set_modtime:ValueError", "Failed to set modification time of %s: %s", p, m);
42+
end
43+
2744
end
2845

2946
%!test

test/TestTime.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ function test_get_modtime(tc)
3232

3333

3434
function test_touch_modtime(tc)
35-
tc.assumeTrue(stdlib.has_java() || stdlib.has_python())
36-
3735
fn = fullfile(tc.td, "modtime.txt");
3836

3937
tc.verifyTrue(stdlib.touch(fn, datetime("yesterday")))
@@ -47,8 +45,6 @@ function test_touch_modtime(tc)
4745

4846

4947
function test_set_modtime(tc)
50-
tc.assumeTrue(stdlib.has_java() || stdlib.has_python())
51-
5248
tc.verifyEqual(stdlib.set_modtime("", datetime("now")), false)
5349
end
5450

0 commit comments

Comments
 (0)