From: Eric Wong Date: Thu, 5 Aug 2021 02:33:40 +0000 (+0000) Subject: lei export-kw: workaround race in updating Maildir locations X-Git-Tag: v1.7.0~522 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=a29946ad3bc49704a512ae3ab31a45bbd66165e2 lei export-kw: workaround race in updating Maildir locations Inotify updates may simultaneously remove or update the location of a message, so ensure we at least have knowledge of the new location if the old one cannot be updated. --- diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm index 82740d59..6dfa03be 100644 --- a/lib/PublicInbox/LeiMailSync.pm +++ b/lib/PublicInbox/LeiMailSync.pm @@ -158,7 +158,13 @@ sub mv_src { my $sth = $self->{dbh}->prepare_cached(<<''); UPDATE blob2name SET name = ? WHERE fid = ? AND oidbin = ? AND name = ? - $sth->execute($newbn, $fid, $oidbin, $$id); + my $nr = $sth->execute($newbn, $fid, $oidbin, $$id); + if ($nr == 0) { # may race with a clear_src, ensure new value exists + $sth = $self->{dbh}->prepare_cached(<<''); +INSERT OR IGNORE INTO blob2name (oidbin, fid, name) VALUES (?, ?, ?) + + $sth->execute($oidbin, $fid, $newbn); + } } # read-only, iterates every oidbin + UID or name for a given folder