From fa3945fe1a2d46cff631a00c32f4433e2d3f54ea Mon Sep 17 00:00:00 2001 From: d-tsuji Date: Mon, 27 Apr 2020 14:05:56 +0900 Subject: [PATCH] fix: bug that causes an error when dirwalking to a non-existent directory. fix: https://github.com/d-tsuji/qiisync/issues/1 --- broker.go | 4 ++++ broker_test.go | 13 ------------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/broker.go b/broker.go index 26be3e6..c0edc9e 100644 --- a/broker.go +++ b/broker.go @@ -143,6 +143,10 @@ func (b *Broker) FetchLocalArticles() (articles map[string]*Article, err error) } func dirwalk(dir string) ([]string, error) { + err := os.MkdirAll(dir, 0755) + if err != nil { + return nil, fmt.Errorf("make dir: %w", err) + } files, err := ioutil.ReadDir(dir) if err != nil { return nil, fmt.Errorf("read dir: %w", err) diff --git a/broker_test.go b/broker_test.go index 622d1a9..8943ef6 100644 --- a/broker_test.go +++ b/broker_test.go @@ -909,12 +909,6 @@ func Test_fetchLocalArticles(t *testing.T) { Local: localConfig{Dir: filepath.Join("testdata", "duplicate")}}}, wantErr: true, }, - { - name: "dummy_dir", - fields: fields{config: &Config{ - Local: localConfig{Dir: "dummy"}}}, - wantErr: true, - }, } if err := os.Chtimes(filepath.Join("testdata", "article", "20_test_article_posted.md"), updateAt, updateAt); err != nil { @@ -1159,13 +1153,6 @@ func Test_dirwalk(t *testing.T) { } } -func Test_dirwalk_dummyDir(t *testing.T) { - _, err := dirwalk("dummy") - if err == nil { - t.Errorf("expect to occur error but nothing: %v", err) - } -} - func setup() (broker *Broker, mux *http.ServeMux, serverURL string, teardown func()) { mux = http.NewServeMux()