Return detailed error when directory is missing

Fixes https://github.com/tus/tusd/issues/98
This commit is contained in:
Marius 2017-01-26 21:46:06 +01:00
parent 3adec97aa5
commit d5004f85a1
2 changed files with 16 additions and 1 deletions

View File

@ -17,6 +17,7 @@ package filestore
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
@ -62,7 +63,10 @@ func (store FileStore) NewUpload(info tusd.FileInfo) (id string, err error) {
// Create .bin file with no content
file, err := os.OpenFile(store.binPath(id), os.O_CREATE|os.O_WRONLY, defaultFilePerm)
if err != nil {
return
if os.IsNotExist(err) {
err = fmt.Errorf("upload directory does not exist: %s", store.Path)
}
return "", err
}
defer file.Close()

View File

@ -72,6 +72,17 @@ func TestFilestore(t *testing.T) {
a.True(os.IsNotExist(err))
}
func TestMissingPath(t *testing.T) {
a := assert.New(t)
store := FileStore{"./path-that-does-not-exist"}
id, err := store.NewUpload(tusd.FileInfo{})
a.Error(err)
a.Equal(err.Error(), "upload directory does not exist: ./path-that-does-not-exist")
a.Equal(id, "")
}
func TestFileLocker(t *testing.T) {
a := assert.New(t)