commit 98774defa0496b92243c1b542f68f33465a0a6eb
parent ac4ad2ffd51eb1f5c9a10d2a45104fe7f8641915
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Sat, 19 Oct 2024 18:55:18 +0900
Fix a bug.
When a file name is changed by a wstat message,
all other fids which hold the same file should be updated.
Diffstat:
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/server.go b/server.go
@@ -1238,7 +1238,18 @@ func sWStat(ctx context.Context, c *conn, rc <-chan *request) {
 				goto resp
 			}
 			if path.Base(r.fid.path) != newStat.Name {
-				r.fid.path = path.Join(path.Dir(r.fid.path), newStat.Name)
+				oldPath := r.fid.path
+				r.fid.path = path.Join(path.Dir(oldPath), newStat.Name)
+				// TODO: I think map[fid.path][]*fid is better.
+				// I think there is a race condition.
+				// e.g. create a file with the old name?
+				c.fPool.Lock()
+				for _, fid := range c.fPool.m {
+					if fid.path == oldPath {
+						fid.path = r.fid.path
+					}
+				}
+				c.fPool.Unlock()
 			}
 			r.ofcall = &RWstat{}
 		resp: