From 4c1f2b99a213bda30a67c11d1d0a3eec456f0e15 Mon Sep 17 00:00:00 2001 From: Adam Kaplan Date: Thu, 1 Oct 2015 13:45:39 -0400 Subject: [PATCH] Ran go formatter --- datastore.go | 2 +- filestore/filestore.go | 54 +++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/datastore.go b/datastore.go index 71db972..f6debf5 100644 --- a/datastore.go +++ b/datastore.go @@ -1,8 +1,8 @@ package tusd import ( + "errors" "io" - "errors" ) // Error indicating that the data store has locked the file for further edits. diff --git a/filestore/filestore.go b/filestore/filestore.go index 4900179..771405e 100644 --- a/filestore/filestore.go +++ b/filestore/filestore.go @@ -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) }