blob: ce0f743d77c6d039ab4c594205c03480249e516c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
implement Newer;
#
# test if a file is up to date
#
include "sys.m";
include "draw.m";
Newer: module
{
init: fn(nil: ref Draw->Context, nil: list of string);
};
init(nil: ref Draw->Context, args: list of string)
{
sys := load Sys Sys->PATH;
if(len args != 3){
sys->fprint(sys->fildes(2), "usage: newer newfile oldfile\n");
raise "fail:usage";
}
args = tl args;
(ok1, d1) := sys->stat(hd args);
if(ok1 < 0)
raise sys->sprint("fail:new:%r");
if(d1.mode & Sys->DMDIR)
raise "fail:new:directory";
(ok2, d2) := sys->stat(hd tl args);
if(ok2 < 0)
raise sys->sprint("fail:old:%r");
if(d2.mode & Sys->DMDIR)
raise "fail:old:directory";
if(d2.mtime > d1.mtime)
raise "fail:older";
}
|