tusd/lockingstore/memorylocker.go

36 lines
616 B
Go
Raw Normal View History

package lockingstore
import (
"github.com/tus/tusd"
)
type MemoryLocker struct {
locks map[string]bool
}
func New() *MemoryLocker {
return &MemoryLocker{
locks: make(map[string]bool),
}
}
func (locker *MemoryLocker) LockUpload(id string) error {
// Ensure file is not locked
if _, ok := locker.locks[id]; ok {
return tusd.ErrFileLocked
}
2015-12-09 19:48:41 +00:00
locker.locks[id] = true
return nil
}
func (locker *MemoryLocker) UnlockUpload(id string) error {
// Deleting a non-existing key does not end in unexpected errors or panic
// since this operation results in a no-op
delete(locker.locks, id)
return nil
}