Skip to content

Commit

Permalink
Merge pull request #29 from mcuadros/memfs-fix-rename
Browse files Browse the repository at this point in the history
memfs: fix Rename leftovers
  • Loading branch information
mcuadros authored May 17, 2017
2 parents cadb3c8 + 0acab88 commit 5249760
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions memfs/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ func (s *storage) move(from, to string) error {
s.files[to].BaseFilename = filepath.Base(to)
s.children[to] = s.children[from]

delete(s.children, from)
delete(s.files, from)
defer func() {
delete(s.children, from)
delete(s.files, from)
delete(s.children[filepath.Dir(from)], filepath.Base(from))
}()

return s.createParent(to, 0644, s.files[to])
}
Expand Down
8 changes: 8 additions & 0 deletions test/fs_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ func (s *FilesystemSuite) TestRename(c *C) {
err := WriteFile(s.FS, "foo", nil, 0644)
c.Assert(err, IsNil)

files, err := s.FS.ReadDir("")
c.Assert(err, IsNil)
c.Assert(files, HasLen, 1)

err = s.FS.Rename("foo", "bar")
c.Assert(err, IsNil)

Expand All @@ -531,8 +535,12 @@ func (s *FilesystemSuite) TestRename(c *C) {
c.Assert(os.IsNotExist(err), Equals, true)

bar, err := s.FS.Stat("bar")
c.Assert(err, IsNil)
c.Assert(bar, NotNil)

files, err = s.FS.ReadDir("")
c.Assert(err, IsNil)
c.Assert(files, HasLen, 1)
}

func (s *FilesystemSuite) TestRenameToDir(c *C) {
Expand Down

0 comments on commit 5249760

Please sign in to comment.