From 739008eaa64e12eea9ef9ecbfb16187f86085290 Mon Sep 17 00:00:00 2001 From: Tyler Treat Date: Tue, 15 Dec 2020 11:43:50 -0700 Subject: [PATCH 1/2] Fix delete stream error when dir is not empty Fix an edge case when deleting a stream directory that has been partially removed. Fixes #297 --- server/api_test.go | 8 ++++++++ server/metadata.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/api_test.go b/server/api_test.go index 7a479a21..a56498c4 100644 --- a/server/api_test.go +++ b/server/api_test.go @@ -3,6 +3,8 @@ package server import ( "context" "fmt" + "os" + "path/filepath" "strconv" "testing" "time" @@ -236,12 +238,18 @@ func TestDeleteStream(t *testing.T) { err = client.CreateStream(context.Background(), "foo", "foo", lift.Partitions(3)) require.NoError(t, err) + _, err = os.Stat(filepath.Join(s1Config.DataDir, "streams", "foo")) + require.NoError(t, err) + stream := s1.metadata.GetStream("foo") require.NotNil(t, stream) err = client.DeleteStream(context.Background(), "foo") require.NoError(t, err) + _, err = os.Stat(filepath.Join(s1Config.DataDir, "streams", "foo")) + require.True(t, os.IsNotExist(err)) + stream = s1.metadata.GetStream("foo") require.Nil(t, stream) diff --git a/server/metadata.go b/server/metadata.go index 3cacbcef..0a1557fe 100644 --- a/server/metadata.go +++ b/server/metadata.go @@ -837,7 +837,7 @@ func (m *metadataAPI) CloseAndDeleteStream(stream *stream) error { // Remove the (now empty) stream data directory streamDataDir := filepath.Join(m.Server.config.DataDir, "streams", stream.GetName()) - err = os.Remove(streamDataDir) + err = os.RemoveAll(streamDataDir) if err != nil { return errors.Wrap(err, "failed to delete stream data directory") } From 27e13f94d9d1ec32e4dca9360aea1cb8e418c325 Mon Sep 17 00:00:00 2001 From: Tyler Treat Date: Tue, 15 Dec 2020 12:37:29 -0700 Subject: [PATCH 2/2] Correct code comment --- server/metadata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/metadata.go b/server/metadata.go index 0a1557fe..38ff984a 100644 --- a/server/metadata.go +++ b/server/metadata.go @@ -835,7 +835,7 @@ func (m *metadataAPI) CloseAndDeleteStream(stream *stream) error { return errors.Wrap(err, "failed to delete stream") } - // Remove the (now empty) stream data directory + // Remove the stream data directory streamDataDir := filepath.Join(m.Server.config.DataDir, "streams", stream.GetName()) err = os.RemoveAll(streamDataDir) if err != nil {