summaryrefslogtreecommitdiff
path: root/lib/MaildirIndexer/Index/ByRef.rakumod
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2019-12-29 18:42:08 +0000
committerdakkar <dakkar@thenautilus.net>2019-12-29 18:42:08 +0000
commit8dfa6a6392aa5b603d09413f5449f9a26d386310 (patch)
tree33901194dba7ef01decb1b2d3456ea65c2f86d2f /lib/MaildirIndexer/Index/ByRef.rakumod
parentbetter scandir (diff)
downloadMaildirIndexer-8dfa6a6392aa5b603d09413f5449f9a26d386310.tar.gz
MaildirIndexer-8dfa6a6392aa5b603d09413f5449f9a26d386310.tar.bz2
MaildirIndexer-8dfa6a6392aa5b603d09413f5449f9a26d386310.zip
handle receiving same file more than once
`scan-dir`, because of `IO.watch`, can emit the same path multiple times; we don't want messing up the index (especially the bayesian one!) because of that
Diffstat (limited to 'lib/MaildirIndexer/Index/ByRef.rakumod')
-rw-r--r--lib/MaildirIndexer/Index/ByRef.rakumod8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/MaildirIndexer/Index/ByRef.rakumod b/lib/MaildirIndexer/Index/ByRef.rakumod
index d044272..f9fc4f9 100644
--- a/lib/MaildirIndexer/Index/ByRef.rakumod
+++ b/lib/MaildirIndexer/Index/ByRef.rakumod
@@ -14,6 +14,10 @@ method dump() {
method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) {
MaildirIndexer::LogTimelineSchema::Index::Add.log: :class('ByRef'),:$mailbox, -> {
+ # ignore adding the same file twice, files in maildirs are
+ # immutable
+ return if %!id-for-file{ $email.path }:exists;
+
my $id = $email.message-id or return;
%!id-for-file{ $email.path } = $id;
%!mailboxes-for-id{ $id }.push($mailbox);
@@ -23,12 +27,12 @@ method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) {
method del-path(IO:D $file, Str:D $mailbox --> Nil) {
MaildirIndexer::LogTimelineSchema::Index::Rm.log: :class('ByRef'),:$mailbox, -> {
- my $id = %!id-for-file{ $file.path }:delete;
+ my $id = %!id-for-file{ $file.path }:delete or return;
with %!mailboxes-for-id{ $id } {
with .grep($mailbox):k -> $pos {
.splice($pos,1);
}
- }
+ }
return;
}
}