mirror of
https://github.com/ZizzyDizzyMC/linx-server.git
synced 2026-01-23 02:14:33 +00:00
Support file locking
TODO: Actually check for locks in cleanup.go
This commit is contained in:
parent
3f503442f1
commit
4512264e84
6 changed files with 70 additions and 7 deletions
|
|
@ -16,6 +16,7 @@ import (
|
|||
type LocalfsBackend struct {
|
||||
metaPath string
|
||||
filesPath string
|
||||
locksPath string
|
||||
}
|
||||
|
||||
type MetadataJSON struct {
|
||||
|
|
@ -127,6 +128,29 @@ func (b LocalfsBackend) writeMetadata(key string, metadata backends.Metadata) er
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b LocalfsBackend) Lock(filename string) (err error) {
|
||||
lockPath := path.Join(b.locksPath, filename)
|
||||
|
||||
lock, err := os.Create(lockPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lock.Close()
|
||||
return
|
||||
}
|
||||
|
||||
func (b LocalfsBackend) Unlock(filename string) (err error) {
|
||||
lockPath := path.Join(b.locksPath, filename)
|
||||
|
||||
err = os.Remove(lockPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (b LocalfsBackend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string, srcIp string) (m backends.Metadata, err error) {
|
||||
filePath := path.Join(b.filesPath, key)
|
||||
|
||||
|
|
@ -201,9 +225,10 @@ func (b LocalfsBackend) List() ([]string, error) {
|
|||
return output, nil
|
||||
}
|
||||
|
||||
func NewLocalfsBackend(metaPath string, filesPath string) LocalfsBackend {
|
||||
func NewLocalfsBackend(metaPath string, filesPath string, locksPath string) LocalfsBackend {
|
||||
return LocalfsBackend{
|
||||
metaPath: metaPath,
|
||||
filesPath: filesPath,
|
||||
locksPath: locksPath,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package s3
|
|||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
|
@ -156,6 +157,16 @@ func unmapMetadata(input map[string]*string) (m backends.Metadata, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (b S3Backend) Lock(filename string) (err error) {
|
||||
log.Printf("Locking is not supported on S3")
|
||||
return
|
||||
}
|
||||
|
||||
func (b S3Backend) Unlock(filename string) (err error) {
|
||||
log.Printf("Locking is not supported on S3")
|
||||
return
|
||||
}
|
||||
|
||||
func (b S3Backend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string, srcIp string) (m backends.Metadata, err error) {
|
||||
tmpDst, err := ioutil.TempFile("", "linx-server-upload")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ type StorageBackend interface {
|
|||
Exists(key string) (bool, error)
|
||||
Head(key string) (Metadata, error)
|
||||
Get(key string) (Metadata, io.ReadCloser, error)
|
||||
Lock(filename string) (error)
|
||||
Unlock(filename string) (error)
|
||||
Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string, srcIp string) (Metadata, error)
|
||||
PutMetadata(key string, m Metadata) error
|
||||
ServeFile(key string, w http.ResponseWriter, r *http.Request) error
|
||||
|
|
@ -25,3 +27,4 @@ type MetaStorageBackend interface {
|
|||
|
||||
var NotFoundErr = errors.New("File not found.")
|
||||
var FileEmptyError = errors.New("Empty file")
|
||||
var FileLockedError = errors.New("Locked file")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue