From 491dc1aeab9b445ee28f972e19a1cbb4cb9f3af7 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 20 Jan 2024 17:30:25 +0000 Subject: look at fs on demand, don't watch it ScanDir (well, fs notifications in raku) is too slow to keep up with actual fs changes (especially when e.g. a file is being downloaded) there's actually no need to watch fs changes, we can just sync the db with the file system we look at each directory --- lib/App/MediaControl/FS.rakumod | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/App/MediaControl/FS.rakumod (limited to 'lib/App/MediaControl/FS.rakumod') diff --git a/lib/App/MediaControl/FS.rakumod b/lib/App/MediaControl/FS.rakumod new file mode 100644 index 0000000..b8f68d2 --- /dev/null +++ b/lib/App/MediaControl/FS.rakumod @@ -0,0 +1,36 @@ +use v6.d; + +class App::MediaControl::FS { + has IO::Path() $.root is required; + has $!extensions; + + submethod TWEAK(:$extensions) { + $!extensions = any($extensions.Slip); + } + + method get-children-of(Str $path) { + my $base = $!root.child($path); + return @() unless $base.d; + + my @children = eager $base.dir( + test => -> $f { + my $based-f = $base.child($f); + + + $based-f.d ?? $f ~~ $*SPEC.curupdir !! + ($based-f.extension ~~ $!extensions) ?? True !! + False; + }, + ); + + return @children.map( + -> $f { + %( name => $f.basename, is_dir => $f.d ); + } + ).sort({ . }); + } + + method exists(Str $path) { + return $!root.child($path).e; + } +} -- cgit v1.2.3