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

@ -313,15 +313,13 @@ func LoginAttemptCleanup(ctx context.Context) error {
})
}
// LoginAttemptRemoveAccount removes all LoginAttempt records for an account
// loginAttemptRemoveAccount removes all LoginAttempt records for an account
// (value must be non-empty).
func LoginAttemptRemoveAccount(ctx context.Context, accountName string) error {
return AuthDB.Write(ctx, func(tx *bstore.Tx) error {
q := bstore.QueryTx[LoginAttempt](tx)
q.FilterNonzero(LoginAttempt{AccountName: accountName})
_, err := q.Delete()
return err
})
func loginAttemptRemoveAccount(tx *bstore.Tx, accountName string) error {
q := bstore.QueryTx[LoginAttempt](tx)
q.FilterNonzero(LoginAttempt{AccountName: accountName})
_, err := q.Delete()
return err
}
// LoginAttemptList returns LoginAttempt records for the accountName. If