When removing an account, wait for the last account reference has gone away before removing the files.

The intent to remove the account is stored in the database. At startup, if
there are any such referenes, they are applied by removing the account
directories and the entry in the database. This ensures the account directory
is properly removed, even on incomplete shutdown.

Don't add an account when its directory already exits.
This commit is contained in:
Mechiel Lukkien
2025-03-15 12:22:04 +01:00
parent c4255a96f8
commit ac4b006ecd
7 changed files with 209 additions and 41 deletions

View File

@ -8,6 +8,8 @@ import (
"testing"
"time"
"github.com/mjl-/bstore"
"github.com/mjl-/mox/mox-"
)
@ -87,7 +89,9 @@ func TestLoginAttempt(t *testing.T) {
tcompare(t, len(l), 2)
// Removing account will keep last entry for mjl2.
err = LoginAttemptRemoveAccount(ctxbg, "mjl1")
err = AuthDB.Write(ctxbg, func(tx *bstore.Tx) error {
return loginAttemptRemoveAccount(tx, "mjl1")
})
tcheck(t, err, "remove login attempt account")
l, err = LoginAttemptList(ctxbg, "", 0)
tcheck(t, err, "list login attempts")