diff options
author | dakkar <dakkar@thenautilus.net> | 2024-01-20 17:30:25 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2024-01-20 17:35:21 +0000 |
commit | 491dc1aeab9b445ee28f972e19a1cbb4cb9f3af7 (patch) | |
tree | b4213dfea7e02f16e286b6b814dc196c19714cdf /lib/App/MediaControl/FS.rakumod | |
parent | quite the ScanDir supply when files are being modified (diff) | |
download | media-control-491dc1aeab9b445ee28f972e19a1cbb4cb9f3af7.tar.gz media-control-491dc1aeab9b445ee28f972e19a1cbb4cb9f3af7.tar.bz2 media-control-491dc1aeab9b445ee28f972e19a1cbb4cb9f3af7.zip |
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
Diffstat (limited to 'lib/App/MediaControl/FS.rakumod')
-rw-r--r-- | lib/App/MediaControl/FS.rakumod | 36 |
1 files changed, 36 insertions, 0 deletions
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({ .<name> }); + } + + method exists(Str $path) { + return $!root.child($path).e; + } +} |