From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 867E81F8C6 for ; Thu, 5 Aug 2021 02:33:40 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] lei export-kw: workaround race in updating Maildir locations Date: Thu, 5 Aug 2021 02:33:40 +0000 Message-Id: <20210805023340.13381-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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