mirror of
https://github.com/ZizzyDizzyMC/linx-server.git
synced 2026-01-23 02:14:33 +00:00
Update localfs.go
This commit is contained in:
parent
b814486d0e
commit
743ef5d7af
1 changed files with 39 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ package localfs
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
|
@ -16,6 +17,7 @@ import (
|
|||
type LocalfsBackend struct {
|
||||
metaPath string
|
||||
filesPath string
|
||||
locksPath string
|
||||
}
|
||||
|
||||
type MetadataJSON struct {
|
||||
|
|
@ -127,6 +129,41 @@ 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) CheckLock(filename string) (locked bool, err error) {
|
||||
lockPath := path.Join(b.locksPath, filename)
|
||||
|
||||
if _, err := os.Stat(lockPath); errors.Is(err, os.ErrNotExist) {
|
||||
return false, nil
|
||||
} else {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, err
|
||||
}
|
||||
|
||||
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 +238,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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue