diff --git a/filestore/filestore.go b/filestore/filestore.go index 5808cac..f1b5c5b 100644 --- a/filestore/filestore.go +++ b/filestore/filestore.go @@ -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() diff --git a/filestore/filestore_test.go b/filestore/filestore_test.go index b66d299..06c1d39 100644 --- a/filestore/filestore_test.go +++ b/filestore/filestore_test.go @@ -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)