summaryrefslogtreecommitdiff
path: root/lib/fileutil/walk.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fileutil/walk.myr')
-rw-r--r--lib/fileutil/walk.myr19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/fileutil/walk.myr b/lib/fileutil/walk.myr
index 851c1f1..6af2af6 100644
--- a/lib/fileutil/walk.myr
+++ b/lib/fileutil/walk.myr
@@ -1,9 +1,12 @@
use std
+use "loopcheck"
+
pkg fileutil =
type walkiter = struct
dirstk : std.dir#[:]
curdir : byte[:][:]
+ loopck : loopcheck
;;
impl iterable walkiter -> byte[:]
@@ -13,9 +16,16 @@ pkg fileutil =
const bywalk = {p
match std.diropen(p)
| `std.Ok d:
- -> [.dirstk = std.sldup([d][:]), .curdir = std.sldup([std.sldup(p)][:])]
+ -> [
+ .dirstk = std.sldup([d][:]),
+ .curdir = std.sldup([std.sldup(p)][:]),
+ .loopck = mkloopcheck(p),
+ ]
| `std.Err e:
- -> [.dirstk = [][:], .curdir = [][:]]
+ -> [
+ .dirstk = [][:],
+ .curdir = [][:]
+ ]
;;
}
@@ -25,6 +35,7 @@ impl iterable walkiter -> byte[:] =
:nextfile
if itp.dirstk.len < 1
+ freeloopcheck(itp.loopck)
-> false
;;
cur = itp.dirstk[itp.dirstk.len - 1]
@@ -33,6 +44,10 @@ impl iterable walkiter -> byte[:] =
| `std.Some "..": goto nextfile
| `std.Some ent:
p = std.pathcat(itp.curdir[itp.curdir.len - 1], ent)
+ if looped(itp.loopck, p)
+ std.slfree(p)
+ goto nextfile
+ ;;
if std.fisdir(p)
match std.diropen(p)
| `std.Ok d: