summaryrefslogtreecommitdiff
path: root/appl/alphabet/fs/newer.b
blob: a278f70a387a475cad7195083f7fd846575355c8 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
implement Newer, Fsmodule;
include "sys.m";
	sys: Sys;
include "draw.m";
include "sh.m";
include "alphabet/reports.m";
	Report: import Reports;
include "alphabet/fs.m";
	fs: Fs;
	Value: import fs;
	Cmpchan, Option: import Fs;

Newer: module {};

badmod(p: string)
{
	sys->fprint(sys->fildes(2), "fs: size: cannot load %s: %r\n", p);
	raise "fail:bad module";
}

types(): string
{
	return "m-d";
}

init()
{
	sys = load Sys Sys->PATH;
	fs = load Fs Fs->PATH;
	if(fs == nil)
		badmod(Fs->PATH);
	fs->init();
}

# select those items in A that are newer than those in B
# or those that exist in A that don't in B.
# if -d flag is given, select all directories in A too.
run(nil: ref Draw->Context, nil: ref Report,
			opts: list of Option, nil: list of ref Value): ref Value
{
	c := chan of (ref Sys->Dir, ref Sys->Dir, chan of int);
	spawn newer(c, opts != nil);
	return ref Value.Vm(c);
}

newer(c: Cmpchan, dflag: int)
{
	while(((d0, d1, reply) := <-c).t2 != nil){
		r: int;
		if(d0 == nil)
			r = 2r10;
		else if(d1 == nil)
			r = 2r01;
		else if(dflag && (d0.mode & Sys->DMDIR))
			r = 2r11;
		else {
			if(d0.mtime > d1.mtime)
				r = 2r01;
			else
				r= 2r10;
		}
		reply <-= r;
	}
}