Skip to content

Commit

Permalink
Merge pull request #299 from liftbridge-io/fix_issue_297
Browse files Browse the repository at this point in the history
Fix delete stream error when dir is not empty
  • Loading branch information
tylertreat authored Dec 16, 2020
2 parents d7f2b01 + 27e13f9 commit 27fb3b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions server/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package server
import (
"context"
"fmt"
"os"
"path/filepath"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions server/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,9 @@ 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.Remove(streamDataDir)
err = os.RemoveAll(streamDataDir)
if err != nil {
return errors.Wrap(err, "failed to delete stream data directory")
}
Expand Down

0 comments on commit 27fb3b1

Please sign in to comment.