Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local: Fix remove by container-relative path #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion local/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ func (c *container) CreateItem(name string) (stow.Item, io.WriteCloser, error) {
}

func (c *container) RemoveItem(id string) error {
return os.Remove(id)
path := id
if !filepath.IsAbs(id) {
path = filepath.Join(c.path, filepath.FromSlash(id))
}
return os.Remove(path)
}

func (c *container) Put(name string, r io.Reader, size int64, metadata map[string]interface{}) (stow.Item, error) {
Expand Down
23 changes: 17 additions & 6 deletions test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,9 @@ func All(t *testing.T, kind string, config stow.Config) {
is.OK(item3)

defer func() {
err := c1.RemoveItem(item1.ID())
is.NoErr(err)
err = c1.RemoveItem(item2.ID())
is.NoErr(err)
err = c1.RemoveItem(item3.ID())
is.NoErr(err)
c1.RemoveItem(item1.ID())
c1.RemoveItem(item2.ID())
c1.RemoveItem(item3.ID())
}()

// make sure we can get a small set of paginated results
Expand Down Expand Up @@ -287,6 +284,20 @@ func All(t *testing.T, kind string, config stow.Config) {
})
is.NoErr(err)
is.Equal(found, 3) // should find three items

//item removal by ID
err = c1.RemoveItem(item2.ID())
is.NoErr(err)
noItem, err = c1copy.Item(item2.ID())
is.Equal(stow.ErrNotFound, err)
is.Nil(noItem)

//item removal by name
err = c1.RemoveItem(item1Name)
is.NoErr(err)
noItem, err = c1copy.Item(item1.ID())
is.Equal(stow.ErrNotFound, err)
is.Nil(noItem)
}

func totalNetFDs(t *testing.T) (int, []byte) {
Expand Down