about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-08-05 02:33:40 +0000
committerEric Wong <e@80x24.org>2021-08-05 21:48:29 +0000
commita29946ad3bc49704a512ae3ab31a45bbd66165e2 (patch)
tree8461bc37a55ded819ecb878ff66e90987db8ec03 /lib/PublicInbox
parent2e1a7378395af3c1db61f26b106befbc42876622 (diff)
downloadpublic-inbox-a29946ad3bc49704a512ae3ab31a45bbd66165e2.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/LeiMailSync.pm8
1 files changed, 7 insertions, 1 deletions
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