summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2017-09-13 01:32:50 -0400
committerOri Bernstein <ori@mmarkovcorp.com>2017-09-13 13:29:31 -0700
commit1f4389df622ed274371d0c134ffd3b1c5a94bd48 (patch)
treed7d8c6062b1c70d079c6a3e01d593b750d275c99 /lib
parentd1432628dfd47f863ae877060921d5f8843b4fc6 (diff)
downloadmc-1f4389df622ed274371d0c134ffd3b1c5a94bd48.tar.gz
Change interface of fileutil.bywalk to fix recursing
Diffstat (limited to 'lib')
-rw-r--r--lib/fileutil/walk.myr39
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/fileutil/walk.myr b/lib/fileutil/walk.myr
index 75ed5e2..851c1f1 100644
--- a/lib/fileutil/walk.myr
+++ b/lib/fileutil/walk.myr
@@ -4,15 +4,19 @@ pkg fileutil =
type walkiter = struct
dirstk : std.dir#[:]
curdir : byte[:][:]
- iterdir : bool
;;
impl iterable walkiter -> byte[:]
- const bywalk : (dir : std.dir# -> walkiter)
+ const bywalk : (dir : byte[:] -> walkiter)
;;
-const bywalk = {d
- -> [.dirstk = std.sldup([d][:]), .curdir = std.sldup([""][:])]
+const bywalk = {p
+ match std.diropen(p)
+ | `std.Ok d:
+ -> [.dirstk = std.sldup([d][:]), .curdir = std.sldup([std.sldup(p)][:])]
+ | `std.Err e:
+ -> [.dirstk = [][:], .curdir = [][:]]
+ ;;
}
impl iterable walkiter -> byte[:] =
@@ -20,6 +24,9 @@ impl iterable walkiter -> byte[:] =
var cur, p
:nextfile
+ if itp.dirstk.len < 1
+ -> false
+ ;;
cur = itp.dirstk[itp.dirstk.len - 1]
match std.dirread(cur)
| `std.Some ".": goto nextfile
@@ -28,26 +35,22 @@ impl iterable walkiter -> byte[:] =
p = std.pathcat(itp.curdir[itp.curdir.len - 1], ent)
if std.fisdir(p)
match std.diropen(p)
- | `std.Ok d: std.slpush(&itp.dirstk, d)
+ | `std.Ok d:
+ std.slpush(&itp.dirstk, d)
+ std.slpush(&itp.curdir, p)
| `std.Err e: /* ? */
+ std.slfree(p)
;;
- std.slpush(&itp.curdir, p)
goto nextfile
- else
- valp# = p
;;
+ valp# = p
-> true
| `std.None:
- /* don't close the directory given to us by the user */
- if itp.dirstk.len > 1
- std.dirclose(itp.dirstk[itp.dirstk.len - 1])
- std.slfree(itp.curdir[itp.curdir.len - 1])
- std.slpop(&itp.curdir)
- std.slpop(&itp.dirstk)
- goto nextfile
- else
- -> false
- ;;
+ std.dirclose(cur)
+ std.slfree(itp.curdir[itp.curdir.len - 1])
+ std.slpop(&itp.curdir)
+ std.slpop(&itp.dirstk)
+ goto nextfile
;;
}