Provide easier way for locking file storage

This commit is contained in:
Marius 2015-12-19 00:21:34 +01:00
parent 83587ca0f8
commit b4c0df187e
2 changed files with 18 additions and 4 deletions

View File

@ -44,9 +44,7 @@ func main() {
} }
var store tusd.DataStore var store tusd.DataStore
store = filestore.FileStore{ store = filestore.New(dir)
Path: dir,
}
if storeSize > 0 { if storeSize > 0 {
store = limitedstore.New(storeSize, store) store = limitedstore.New(storeSize, store)

View File

@ -15,6 +15,7 @@ import (
"os" "os"
"github.com/tus/tusd" "github.com/tus/tusd"
"github.com/tus/tusd/lockingstore"
"github.com/tus/tusd/uid" "github.com/tus/tusd/uid"
) )
@ -24,10 +25,25 @@ var defaultFilePerm = os.FileMode(0775)
// methods. // methods.
type FileStore struct { type FileStore struct {
// Relative or absolute path to store files in. FileStore does not check // Relative or absolute path to store files in. FileStore does not check
// whether the path exists, you os.MkdirAll in this case on your own. // whether the path exists, use os.MkdirAll in this case on your own.
Path string Path string
} }
// New creates a new file based storage backend. The directory specified will
// be used as the only storage entry. This method does not check
// whether the path exists, use os.MkdirAll to ensure.
// In addition, a locking mechanism is provided using lockingstore.LockingStore
// and FileLocker.
func New(path string) tusd.DataStore {
store := FileStore{path}
locker := FileLocker{path}
return lockingstore.LockingStore{
DataStore: &store,
Locker: &locker,
}
}
func (store FileStore) NewUpload(info tusd.FileInfo) (id string, err error) { func (store FileStore) NewUpload(info tusd.FileInfo) (id string, err error) {
id = uid.Uid() id = uid.Uid()
info.ID = id info.ID = id