mirror of
https://github.com/mjl-/mox.git
synced 2025-07-10 09:54:40 +03:00
when removing account, remove its data directory instead of leaving it around
recreating the account would resurface the old messages, certainly not what you'ld expect. it's about time to just remove the files. we do ask admins to confirm that when removing through admin interface. it's also in the "mox config account rm" help output now. for issue #162 by RobSlgm with feedback from x8x, thanks!
This commit is contained in:
@ -1024,6 +1024,18 @@ func AccountRemove(ctx context.Context, account string) (rerr error) {
|
||||
if err := writeDynamic(ctx, log, nc); err != nil {
|
||||
return fmt.Errorf("writing domains.conf: %w", err)
|
||||
}
|
||||
|
||||
odir := filepath.Join(DataDirPath("accounts"), account)
|
||||
tmpdir := filepath.Join(DataDirPath("tmp"), "oldaccount-"+account)
|
||||
if err := os.Rename(odir, tmpdir); err != nil {
|
||||
log.Errorx("moving old account data directory out of the way", err, slog.String("account", account))
|
||||
return fmt.Errorf("account removed, but account data directory %q could not be moved out of the way: %v", odir, err)
|
||||
}
|
||||
if err := os.RemoveAll(tmpdir); err != nil {
|
||||
log.Errorx("removing old account data directory", err, slog.String("account", account))
|
||||
return fmt.Errorf("account removed, its data directory moved to %q, but removing failed: %v", odir, err)
|
||||
}
|
||||
|
||||
log.Info("account removed", slog.String("account", account))
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user