From 375827657ffbb153d30778070a86c6873ee5b3c5 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 30 Dec 2017 14:41:38 +0000 Subject: handle file deletion --- lib/Ultramarine/Model/Collection.pm6 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib/Ultramarine/Model/Collection.pm6') diff --git a/lib/Ultramarine/Model/Collection.pm6 b/lib/Ultramarine/Model/Collection.pm6 index e894f1c..4a09b46 100644 --- a/lib/Ultramarine/Model/Collection.pm6 +++ b/lib/Ultramarine/Model/Collection.pm6 @@ -21,20 +21,27 @@ class Ultramarine::Model::Collection { CATCH { default { .perl.say } } react whenever $.dirscan.scan -> $path { when $path ~~ Ultramarine::Model::DirScanner::EndOfScan { - # we should use this to check that all the files in + # we use this to check that all the files in # the db have been seen, and delete those that haven't - # - # calling db.remove-unseen-files, plus db.remove-empty + $.db.remove-unseen-files(); $!mark-ready.keep(True); } when $path ~~ IO::Path & :f { my $mtime = $path.modified.floor; - # call db.ensure-song and db.seen-file + # we only care to keep track of which files we've + # seen during the initial scan (so we can clean up + # rows for files that were removed while we were + # not running); after that, we'll get notification + # of deleted files, and we'll remove those + $.db.seen-file(:$path) unless $.is-ready.status ~~ Kept; unless $.db.is-up-to-date(:$path,:$mtime) { my %metadata = $.file-class.new(:$path).metadata; $.db.ensure-song(:$path,:$mtime,:%metadata) if %metadata.keys; } } + when $path ~~ IO::Path & :!f { + $.db.ensure-file-absent(:$path); + } } } } -- cgit v1.2.3