Ran go formatter

This commit is contained in:
Adam Kaplan 2015-10-01 13:45:39 -04:00
parent 766dabc238
commit 4c1f2b99a2
2 changed files with 28 additions and 28 deletions

View File

@ -1,8 +1,8 @@
package tusd
import (
"errors"
"io"
"errors"
)
// Error indicating that the data store has locked the file for further edits.

View File

@ -7,7 +7,7 @@
package filestore
import (
"bytes"
"bytes"
"encoding/json"
"io"
"io/ioutil"
@ -25,16 +25,16 @@ type FileStore struct {
// 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.
Path string
locks map[string]bool
locks map[string]bool
}
// NewFileStore creates a new FileStore instance.
func NewFileStore(path string) (store *FileStore) {
store = &FileStore{
Path: path,
locks: make(map[string]bool),
}
return
store = &FileStore{
Path: path,
locks: make(map[string]bool),
}
return
}
func (store *FileStore) NewUpload(info tusd.FileInfo) (id string, err error) {
@ -55,11 +55,11 @@ func (store *FileStore) NewUpload(info tusd.FileInfo) (id string, err error) {
func (store *FileStore) WriteChunk(id string, offset int64, src io.Reader) (int64, error) {
if !store.getLock(id) {
return 0, tusd.ErrFileLocked
return 0, tusd.ErrFileLocked
}
defer store.clearLock(id)
file, err := os.OpenFile(store.binPath(id), os.O_WRONLY|os.O_APPEND, defaultFilePerm)
defer store.clearLock(id)
file, err := os.OpenFile(store.binPath(id), os.O_WRONLY|os.O_APPEND, defaultFilePerm)
if err != nil {
return 0, err
}
@ -75,7 +75,7 @@ func (store *FileStore) WriteChunk(id string, offset int64, src io.Reader) (int6
}
func (store *FileStore) GetInfo(id string) (info tusd.FileInfo, err error) {
data, err := ioutil.ReadFile(store.infoPath(id))
data, err := ioutil.ReadFile(store.infoPath(id))
if err != nil {
return info, err
}
@ -85,17 +85,17 @@ func (store *FileStore) GetInfo(id string) (info tusd.FileInfo, err error) {
func (store *FileStore) GetReader(id string) (io.Reader, error) {
if !store.getLock(id) {
return bytes.NewReader(make([]byte, 0)), tusd.ErrFileLocked
return bytes.NewReader(make([]byte, 0)), tusd.ErrFileLocked
}
defer store.clearLock(id)
return os.Open(store.binPath(id))
defer store.clearLock(id)
return os.Open(store.binPath(id))
}
func (store *FileStore) Terminate(id string) error {
if !store.getLock(id) {
return tusd.ErrFileLocked
}
defer store.clearLock(id)
if !store.getLock(id) {
return tusd.ErrFileLocked
}
defer store.clearLock(id)
if err := os.Remove(store.infoPath(id)); err != nil {
return err
}
@ -142,16 +142,16 @@ func (store *FileStore) setOffset(id string, offset int64) error {
// getLock obtains a lock on reading/writing data for the given file ID.
func (store *FileStore) getLock(id string) (hasLock bool) {
if _, locked := store.locks[id]; locked {
hasLock = false
return
}
store.locks[id] = true
hasLock = true
return
if _, locked := store.locks[id]; locked {
hasLock = false
return
}
store.locks[id] = true
hasLock = true
return
}
// clearLock removes the lock for the given file ID.
func (store *FileStore) clearLock(id string) {
delete(store.locks, id)
delete(store.locks, id)
}