-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.goal
22 lines (22 loc) · 1.16 KB
/
fs.goal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/ We define some common portable error messages as globals for convenience.
ErrInvalid:"invalid argument" / EINVAL
ErrPermission:"permission denied" / EACCESS | EPERM
ErrExist:"file already exists" / EEXIST | ENOTEMPTY
ErrNotExist:"file does not exist" / ENOENT
ErrClosed:"file already closed"
/ join[dir;file] is a faster simplified path.join combining a dir path (assumed
/ to be clean) with the base name of a file.
join:{?[x~".";y;"$x/$y"]}
/ ls[fs] returns ..[dir:I;path:S] with all non-dot files in file system fs.
ls:{[fs]{[fs;path]
st:fs stat path; and[st;st..dir;d:fs read path]or:..[dir:!0;path:!""]
d@:&~d..name[;;1]="."; paths:join'[path;d..name]; dirs:paths@&d..dir
r:o[fs]'dirs; dir:d..dir,/r[;"dir"]; path:paths,/r[;"path"]
..[dir;path]}[fs;"."]}
/ walk[f;g;x;fs] folds over fs with f[x;path;name;dir] using seed x, skipping
/ if g[path;name], where name is the base name of path, and dir is true for
/ directories. It stops early if f returns an error.
walk:{[f;g;x;fs]{[fs;f;g;x;path;name;dir]
g[path;name]and:x; ("e"~@x:f[x;path;name;dir])and:x; and[dir;d:fs read path]or:x
o[fs;f;g]/[~"e"~@:;x;join'[path;d..name];d..name;d..dir]}[fs;f;g;x;".";".";1]}
1