From d5004f85a1656c52e4ab10d1eebf9027a50fa065 Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 26 Jan 2017 21:46:06 +0100 Subject: [PATCH] Return detailed error when directory is missing Fixes https://github.com/tus/tusd/issues/98 --- filestore/filestore.go | 6 +++++- filestore/filestore_test.go | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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)