]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei export-kw: workaround race in updating Maildir locations
authorEric Wong <e@80x24.org>
Thu, 5 Aug 2021 02:33:40 +0000 (02:33 +0000)
committerEric Wong <e@80x24.org>
Thu, 5 Aug 2021 21:48:29 +0000 (21:48 +0000)
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.

lib/PublicInbox/LeiMailSync.pm

index 82740d59b69c42e84d94dfa0faf4be2f1182bc4a..6dfa03be2feaf2063d3681626a869271423f36fa 100644 (file)
@@ -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