Skip to content

Commit ddfaadb

Browse files
committed
memfs: fix Rename from root to dir
1 parent 0661b96 commit ddfaadb

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

memfs/storage.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,25 @@ func (s *storage) Rename(from, to string) error {
126126
from := ops[0]
127127
to := ops[1]
128128

129-
s.files[to] = s.files[from]
130-
s.children[to] = s.children[from]
131-
delete(s.children, from)
132-
delete(s.files, from)
129+
if err := s.move(from, to); err != nil {
130+
return err
131+
}
133132
}
134133

135134
return nil
136135
}
137136

137+
func (s *storage) move(from, to string) error {
138+
s.files[to] = s.files[from]
139+
s.files[to].BaseFilename = filepath.Base(to)
140+
s.children[to] = s.children[from]
141+
142+
delete(s.children, from)
143+
delete(s.files, from)
144+
145+
return s.createParent(to, 0644, s.files[to])
146+
}
147+
138148
func (s *storage) Remove(path string) error {
139149
path = filepath.Clean(path)
140150

0 commit comments

Comments
 (0)