1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-27 14:37:17 +00:00

datastore: Concurrency fix, closes #77

This commit is contained in:
James Hillyerd
2018-03-09 14:02:15 -08:00
parent a89b6bbca2
commit a3877e4f4b
6 changed files with 111 additions and 1 deletions

View File

@@ -51,6 +51,7 @@ func countGenerator(c chan int) {
// FileDataStore implements DataStore aand is the root of the mail storage
// hiearchy. It provides access to Mailbox objects
type FileDataStore struct {
hashLock datastore.HashLock
path string
mailPath string
messageCap int
@@ -139,6 +140,15 @@ func (ds *FileDataStore) AllMailboxes() ([]datastore.Mailbox, error) {
return mailboxes, nil
}
func (ds *FileDataStore) LockFor(emailAddress string) (*sync.RWMutex, error) {
name, err := stringutil.ParseMailboxName(emailAddress)
if err != nil {
return nil, err
}
hash := stringutil.HashMailboxName(name)
return ds.hashLock.Get(hash), nil
}
// FileMailbox implements Mailbox, manages the mail for a specific user and
// correlates to a particular directory on disk.
type FileMailbox struct {