From 3138213f3913a623163514d63d8c8f71a673e989 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Wed, 27 Apr 2022 08:38:43 -0300 Subject: [PATCH] Let MailboxManager#unPair() return a boolean for whether it could wipe the mailbox --- .../briarproject/bramble/api/mailbox/MailboxManager.java | 6 +++++- .../briarproject/bramble/mailbox/MailboxManagerImpl.java | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/mailbox/MailboxManager.java b/bramble-api/src/main/java/org/briarproject/bramble/api/mailbox/MailboxManager.java index 784fff21d..d2c88aebb 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/mailbox/MailboxManager.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/mailbox/MailboxManager.java @@ -45,7 +45,11 @@ public interface MailboxManager { /** * Unpairs the owner's mailbox and tries to wipe it. * As this makes a network call, it should be run on the {@link IoExecutor}. + * + * @return true if we could wipe the mailbox, false if we couldn't. + * It is advised to inform the user to wipe the mailbox themselves, + * if we failed to wipe it. */ @IoExecutor - void unPair() throws DbException; + boolean unPair() throws DbException; } diff --git a/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxManagerImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxManagerImpl.java index d17401559..1671c0519 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxManagerImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/mailbox/MailboxManagerImpl.java @@ -132,17 +132,19 @@ class MailboxManagerImpl implements MailboxManager { } @Override - public void unPair() throws DbException { + public boolean unPair() throws DbException { MailboxProperties properties = db.transactionWithNullableResult(true, mailboxSettingsManager::getOwnMailboxProperties); + boolean wasWiped; try { api.wipeMailbox(properties); + wasWiped = true; } catch (IOException | MailboxApi.ApiException e) { - // We wipe on a best-effort basis. - // If we can't do it, we still unpair. logException(LOG, WARNING, e); + wasWiped = false; } db.transaction(false, mailboxSettingsManager::removeOwnMailboxProperties); + return wasWiped; } }