mirror of
https://github.com/mjl-/mox.git
synced 2025-07-10 07:54:40 +03:00
add per-account quota for total message size disk usage
so a single user cannot fill up the disk. by default, there is (still) no limit. a default can be set in the config file for all accounts, and a per-account max size can be set that would override any global setting. this does not take into account disk usage of the index database. and also not of any file system overhead.
This commit is contained in:
21
ctl.go
21
ctl.go
@ -685,11 +685,13 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
|
||||
acc.WithWLock(func() {
|
||||
var changes []store.Change
|
||||
err = acc.DB.Write(ctx, func(tx *bstore.Tx) error {
|
||||
return bstore.QueryTx[store.Mailbox](tx).ForEach(func(mb store.Mailbox) error {
|
||||
var totalSize int64
|
||||
err := bstore.QueryTx[store.Mailbox](tx).ForEach(func(mb store.Mailbox) error {
|
||||
mc, err := mb.CalculateCounts(tx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("calculating counts for mailbox %q: %w", mb.Name, err)
|
||||
}
|
||||
totalSize += mc.Size
|
||||
|
||||
if !mb.HaveCounts || mc != mb.MailboxCounts {
|
||||
_, err := fmt.Fprintf(w, "for %s setting new counts %s (was %s)\n", mb.Name, mc, mb.MailboxCounts)
|
||||
@ -703,6 +705,23 @@ func servectlcmd(ctx context.Context, ctl *ctl, shutdown func()) {
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
du := store.DiskUsage{ID: 1}
|
||||
if err := tx.Get(&du); err != nil {
|
||||
return fmt.Errorf("get disk usage: %v", err)
|
||||
}
|
||||
if du.MessageSize != totalSize {
|
||||
_, err := fmt.Fprintf(w, "setting new total message size %d (was %d)\n", totalSize, du.MessageSize)
|
||||
ctl.xcheck(err, "write")
|
||||
du.MessageSize = totalSize
|
||||
if err := tx.Update(&du); err != nil {
|
||||
return fmt.Errorf("update disk usage: %v", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
ctl.xcheck(err, "write transaction for mailbox counts")
|
||||
|
||||
|
Reference in New Issue
Block a user