From 99da99dfb9735a5ceba6bd945cfb0367ad0fb015 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 16 Jul 2024 08:02:21 +0200 Subject: [PATCH] Cloud sync: prevent constraint violation --- .../java/eu/faircode/email/CloudSync.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/CloudSync.java b/app/src/main/java/eu/faircode/email/CloudSync.java index fcd88eeb17..440ca98fae 100644 --- a/app/src/main/java/eu/faircode/email/CloudSync.java +++ b/app/src/main/java/eu/faircode/email/CloudSync.java @@ -448,19 +448,27 @@ public class CloudSync { } } else { if (left != null) { - left.account = raccount.id; - left.setProperties(); - left.setSpecials(raccount); - left.id = db.folder().insertFolder(left); - raccount.swipe_left = left.id; + EntityFolder existing = db.folder().getFolderByName(raccount.id, left.name); + if (existing == null) { + left.account = raccount.id; + left.setProperties(); + left.setSpecials(raccount); + left.id = db.folder().insertFolder(left); + raccount.swipe_left = left.id; + } else + raccount.swipe_left = existing.id; } if (right != null) { - right.account = raccount.id; - right.setProperties(); - right.setSpecials(raccount); - right.id = db.folder().insertFolder(right); - raccount.swipe_right = right.id; + EntityFolder existing = db.folder().getFolderByName(raccount.id, right.name); + if (existing == null) { + right.account = raccount.id; + right.setProperties(); + right.setSpecials(raccount); + right.id = db.folder().insertFolder(right); + raccount.swipe_right = right.id; + } else + raccount.swipe_right = existing.id; } db.account().setAccountSwipes(raccount.id, raccount.swipe_left, raccount.swipe_right);