Skip to content

Commit

Permalink
memfs: fix Rename from root to dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed Apr 17, 2017
1 parent 0661b96 commit ddfaadb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions memfs/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,25 @@ func (s *storage) Rename(from, to string) error {
from := ops[0]
to := ops[1]

s.files[to] = s.files[from]
s.children[to] = s.children[from]
delete(s.children, from)
delete(s.files, from)
if err := s.move(from, to); err != nil {
return err
}
}

return nil
}

func (s *storage) move(from, to string) error {
s.files[to] = s.files[from]
s.files[to].BaseFilename = filepath.Base(to)
s.children[to] = s.children[from]

delete(s.children, from)
delete(s.files, from)

return s.createParent(to, 0644, s.files[to])
}

func (s *storage) Remove(path string) error {
path = filepath.Clean(path)

Expand Down

0 comments on commit ddfaadb

Please sign in to comment.