From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 04/10] lei_mail_sync: make rename_folder more robust
Date: Tue, 31 Aug 2021 11:21:20 +0000 [thread overview]
Message-ID: <20210831112126.13406-5-e@80x24.org> (raw)
In-Reply-To: <20210831112126.13406-1-e@80x24.org>
We need to account for past canonicalization errors and deal
with cases which violate uniqueness constraints in
mail_sync.sqlite3
---
lib/PublicInbox/LeiMailSync.pm | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm
index 56468c78..275e0cc4 100644
--- a/lib/PublicInbox/LeiMailSync.pm
+++ b/lib/PublicInbox/LeiMailSync.pm
@@ -412,11 +412,24 @@ sub forget_folder {
# only used for changing canonicalization errors
sub rename_folder {
my ($self, $old, $new) = @_;
- my $fid = delete($self->{fmap}->{$old}) //
+ my $ofid = delete($self->{fmap}->{$old}) //
fid_for($self, $old) // return;
- $self->{dbh}->do(<<EOM, undef, $new, $fid);
+ eval {
+ $self->{dbh}->do(<<EOM, undef, $new, $ofid);
UPDATE folders SET loc = ? WHERE fid = ?
EOM
+ };
+ if ($@ =~ /\bunique\b/i) {
+ my $nfid = $self->{fmap}->{$new} // fid_for($self, $new);
+ for my $t (qw(blob2name blob2num)) {
+ $self->{dbh}->do(<<EOM, undef, $nfid, $ofid);
+UPDATE OR REPLACE $t SET fid = ? WHERE fid = ?
+EOM
+ }
+ $self->{dbh}->do(<<EOM, undef, $ofid);
+DELETE FROM folders WHERE fid = ?
+EOM
+ }
}
sub imap_oidbin ($$$) {
next prev parent reply other threads:[~2021-08-31 11:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-31 11:21 [PATCH 00/10] lei: several bug fixes and refinements Eric Wong
2021-08-31 11:21 ` [PATCH 01/10] lei_mail_sync: forget_folder: simplify code Eric Wong
2021-08-31 11:21 ` [PATCH 02/10] lei prune-mail-sync: handle --all (no args) Eric Wong
2021-08-31 11:21 ` [PATCH 03/10] lei_mail_sync: simplify group2folders Eric Wong
2021-08-31 11:21 ` Eric Wong [this message]
2021-08-31 11:21 ` [PATCH 05/10] t/lei-watch: avoid race between glob + readlink Eric Wong
2021-08-31 11:21 ` [PATCH 06/10] lei note-event: always flush changes on daemon exit Eric Wong
2021-08-31 11:21 ` [PATCH 07/10] lei: refresh watches before MUA spawn for Maildir Eric Wong
2021-08-31 11:21 ` [PATCH 08/10] lei_mail_sync: set_src uses binary OIDs Eric Wong
2021-08-31 11:21 ` [PATCH 09/10] lei: fix error reporting from lei/store -> lei-daemon Eric Wong
2021-08-31 11:21 ` [PATCH 10/10] lei/store: correctly delete entries from over Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210831112126.13406-5-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).