fix wstat panic on session rename
OnRename callback already rewrites fid paths, so by the time wstat's fid update runs, f.path has changed. Use relPath for the new path computation instead of slicing f.path.
This commit is contained in:
parent
4faa341558
commit
18aaddd8b1
16
server.go
16
server.go
|
|
@ -948,15 +948,17 @@ func (s *Server) wstat(cs *connState, fc *plan9.Fcall) *plan9.Fcall {
|
|||
if err := st.Rename(relPath, newDir.Name); err != nil {
|
||||
return errFcall(fc, err.Error())
|
||||
}
|
||||
// Update fid path.
|
||||
// Update fid path (for non-session renames; session renames are
|
||||
// handled by the OnRename callback which rewrites all affected fids).
|
||||
for _, r := range s.storeRoutes() {
|
||||
if strings.HasPrefix(f.path, r.prefix) {
|
||||
// Replace the last path component with the new name.
|
||||
parent := f.path[:len(f.path)-len(oldName)]
|
||||
cs.mu.Lock()
|
||||
f.path = parent + newDir.Name
|
||||
f.qid.Path = qidPath(f.path)
|
||||
cs.mu.Unlock()
|
||||
newPath := r.prefix + relPath[:len(relPath)-len(oldName)] + newDir.Name
|
||||
if newPath != f.path {
|
||||
cs.mu.Lock()
|
||||
f.path = newPath
|
||||
f.qid.Path = qidPath(f.path)
|
||||
cs.mu.Unlock()
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue