From d5679cd0e7759a3fdcec2dc33640c467c25d171d Mon Sep 17 00:00:00 2001 From: James Wang Date: Wed, 9 Jan 2019 18:33:36 -0800 Subject: [PATCH 1/3] Use Dir instead of Base --- loader/directory_refresher.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loader/directory_refresher.go b/loader/directory_refresher.go index 7796f56..7e17935 100644 --- a/loader/directory_refresher.go +++ b/loader/directory_refresher.go @@ -12,8 +12,8 @@ func (d *DirectoryRefresher) WatchDirectory(runtimePath string, appDirPath strin } func (d *DirectoryRefresher) ShouldRefresh(path string, op FileSystemOp) bool { - if filepath.Base(path) == d.currDir && - op == Write || op == Create || op == Chmod { + if filepath.Dir(path) == d.currDir && + (op == Write || op == Create || op == Chmod) { return true } return false From 836e2003759c3c273a4fa5bb111e4ae990456874 Mon Sep 17 00:00:00 2001 From: James Wang Date: Wed, 9 Jan 2019 23:14:32 -0800 Subject: [PATCH 2/3] add write test --- loader/loader_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/loader/loader_test.go b/loader/loader_test.go index 7119e33..cf032a6 100644 --- a/loader/loader_test.go +++ b/loader/loader_test.go @@ -10,10 +10,10 @@ import ( "time" - stats "github.com/lyft/gostats" + "github.com/lyft/gostats" logger "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" -) + ) var nullScope = stats.NewStore(stats.NewNullSink(), false) @@ -158,4 +158,17 @@ func TestDirectoryRefresher(t *testing.T) { snapshot = loader.Snapshot() assert.Equal("hello2", snapshot.Get("file2")) + + // Write to the file + f, err := os.OpenFile(appDir+"/file2", os.O_RDWR, os.ModeAppend) + assert.NoError(err) + _, err = f.WriteString("hello3") + assert.NoError(err) + f.Sync() + + // Wait for the update + <-runtime_update + + snapshot = loader.Snapshot() + assert.Equal("hello3", snapshot.Get("file2")) } From 243e2aea14a8f67b6ada1435ef0616f637555c3f Mon Sep 17 00:00:00 2001 From: James Wang Date: Thu, 10 Jan 2019 01:42:02 -0800 Subject: [PATCH 3/3] fix imports --- loader/loader_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loader/loader_test.go b/loader/loader_test.go index cf032a6..262a7d1 100644 --- a/loader/loader_test.go +++ b/loader/loader_test.go @@ -10,10 +10,10 @@ import ( "time" - "github.com/lyft/gostats" + stats "github.com/lyft/gostats" logger "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" - ) +) var nullScope = stats.NewStore(stats.NewNullSink(), false)