diff options
author | dakkar <dakkar@thenautilus.net> | 2019-12-29 18:42:08 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2019-12-29 18:42:08 +0000 |
commit | 8dfa6a6392aa5b603d09413f5449f9a26d386310 (patch) | |
tree | 33901194dba7ef01decb1b2d3456ea65c2f86d2f /lib/MaildirIndexer/Index/ByAddresses.rakumod | |
parent | better scandir (diff) | |
download | MaildirIndexer-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/ByAddresses.rakumod')
-rw-r--r-- | lib/MaildirIndexer/Index/ByAddresses.rakumod | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/MaildirIndexer/Index/ByAddresses.rakumod b/lib/MaildirIndexer/Index/ByAddresses.rakumod index b83a239..ab0d5bb 100644 --- a/lib/MaildirIndexer/Index/ByAddresses.rakumod +++ b/lib/MaildirIndexer/Index/ByAddresses.rakumod @@ -31,6 +31,10 @@ submethod account-for(Str @addresses,Str $mailbox,Int $step) { method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) { MaildirIndexer::LogTimelineSchema::Index::Add.log: :class('ByAddresses'),:$mailbox, -> { + # ignore adding the same file twice, files in maildirs are + # immutable + return if %!addresses-for-file{ $email.path }:exists; + my Str @addresses = $email.addresses or return; %!addresses-for-file{ $email.path } = @addresses; @@ -42,7 +46,7 @@ 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('ByAddresses'),:$mailbox, -> { - my Str @addresses = %!addresses-for-file{$file.path} or return; + my Str @addresses = %!addresses-for-file{$file.path}:delete or return; self.account-for(@addresses,$mailbox,-1); |