From f36f62b80cbe2d717b41cbea5b37e94e5ce3cf2d Mon Sep 17 00:00:00 2001 From: chihe Date: Thu, 13 Feb 2025 17:23:20 +0800 Subject: [PATCH] fix(client): update fullpath and pinos when excuting rename opration close:#21990545 Signed-off-by: chihe --- client/fs/dir.go | 26 +++++++++++++++++++++++--- client/fs/file.go | 2 +- client/fs/super.go | 2 +- sdk/data/stream/extent_client.go | 3 ++- sdk/data/stream/stream_reader.go | 1 + 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/client/fs/dir.go b/client/fs/dir.go index 273bba982..627f794d2 100644 --- a/client/fs/dir.go +++ b/client/fs/dir.go @@ -702,17 +702,26 @@ func (d *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDir fs.Nod } d.super.fslock.Lock() node, ok := d.super.nodeCache[srcInode] + fullPath := path.Join(dstDir.fullPath, req.NewName) if ok && srcInode != 0 { if dir, ok := node.(*Dir); ok { dir.name = req.NewName dir.parentIno = dstDir.info.Inode + dir.pinos = append(dstDir.pinos, dir.info.Inode) + dir.setFullPath(fullPath) } else { file := node.(*File) file.name = req.NewName file.parentIno = dstDir.info.Inode + file.pinos = dstDir.pinos + file.setFullPath(fullPath) } } - for _, node := range d.super.nodeCache { + for ino, node := range d.super.nodeCache { + // fullPath is already changed + if ino == srcInode { + continue + } if dir, ok := node.(*Dir); ok { if containsInode(dir.pinos, srcInode) { dir.fullPath = replacePathPart(dir.fullPath, req.OldName, req.NewName) @@ -1055,7 +1064,7 @@ func (d *Dir) Removexattr(ctx context.Context, req *fuse.RemovexattrRequest) err } func (d *Dir) setFullPath(fullPath string) { - d.fullPath = fullPath + d.fullPath = fixUnixPath(fullPath) } func (d *Dir) addParentInode(inos []uint64) { @@ -1110,7 +1119,7 @@ func replacePathPart(path, oldPart, newPart string) string { parts[i] = strings.ReplaceAll(part, oldPart, newPart) } } - return filepath.Join(parts...) + return fixUnixPath(filepath.Join(parts...)) } func containsInode(pinos []uint64, inode uint64) bool { @@ -1121,3 +1130,14 @@ func containsInode(pinos []uint64, inode uint64) bool { } return false } + +func isValidUnixPath(path string) bool { + return strings.HasPrefix(path, "/") +} + +func fixUnixPath(path string) string { + if !isValidUnixPath(path) { + return "/" + path + } + return path +} diff --git a/client/fs/file.go b/client/fs/file.go index b2b448030..b0782a971 100644 --- a/client/fs/file.go +++ b/client/fs/file.go @@ -127,7 +127,7 @@ func (f *File) getParentPath() string { } func (f *File) setFullPath(fullPath string) { - f.fullPath = fullPath + f.fullPath = fixUnixPath(fullPath) } func (f *File) addParentInode(inos []uint64) { diff --git a/client/fs/super.go b/client/fs/super.go index 45ca04d9a..d85bf35e3 100644 --- a/client/fs/super.go +++ b/client/fs/super.go @@ -369,7 +369,7 @@ func (s *Super) Root() (fs.Node, error) { root := NewDir(s, inode, inode.Inode, "") root.(*Dir).setFullPath(s.subDir) root.(*Dir).addParentInode([]uint64{inode.Inode}) - log.LogInfof("Super:root patch is(%v)", s.subDir) + log.LogInfof("Super:root path is(%v)", s.subDir) return root, nil } diff --git a/sdk/data/stream/extent_client.go b/sdk/data/stream/extent_client.go index 83c21f51a..8c49d5fbc 100644 --- a/sdk/data/stream/extent_client.go +++ b/sdk/data/stream/extent_client.go @@ -399,7 +399,8 @@ retry: if config.NeedRemoteCache { client.RemoteCache.Init(client) } else { - log.LogInfof("NewExtentClient not init remoteCache, config.NeedRemoteCahe %v", config.NeedRemoteCache) + log.LogInfof("NewExtentClient for (%v) not init remoteCache, config.NeedRemoteCache %v", client.volumeName, + config.NeedRemoteCache) } return diff --git a/sdk/data/stream/stream_reader.go b/sdk/data/stream/stream_reader.go index 0bb3a145a..66a844296 100644 --- a/sdk/data/stream/stream_reader.go +++ b/sdk/data/stream/stream_reader.go @@ -63,6 +63,7 @@ type Streamer struct { aheadReadEnable bool bloomStatus bool aheadReadWindow *AheadReadWindow + fullPath string } type bcacheKey struct {