diff options
| author | chrislu <chris.lu@gmail.com> | 2022-01-11 23:44:48 -0800 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-01-11 23:44:48 -0800 |
| commit | 2dcb8cb93b951bd8457cdb670edf2146b068a836 (patch) | |
| tree | dfbe0e451b3c0f32204cd52e8ea3a617a8ca201f /weed/filesys/dir_rename.go | |
| parent | 5bb37d5905bbc2b091540ff96e0b1389e1016029 (diff) | |
| download | seaweedfs-2dcb8cb93b951bd8457cdb670edf2146b068a836.tar.xz seaweedfs-2dcb8cb93b951bd8457cdb670edf2146b068a836.zip | |
POSIX: ensure file and directory inodes are different
this is just an in memory representation.
POSIX wants different inode numbers for the same named file or directory.
Diffstat (limited to 'weed/filesys/dir_rename.go')
| -rw-r--r-- | weed/filesys/dir_rename.go | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/weed/filesys/dir_rename.go b/weed/filesys/dir_rename.go index 01a8df175..6628b0799 100644 --- a/weed/filesys/dir_rename.go +++ b/weed/filesys/dir_rename.go @@ -84,11 +84,13 @@ func (dir *Dir) handleRenameResponse(ctx context.Context, resp *filer_pb.StreamR oldParent, newParent := util.FullPath(resp.Directory), util.FullPath(resp.EventNotification.NewParentPath) oldName, newName := resp.EventNotification.OldEntry.Name, resp.EventNotification.NewEntry.Name + isDirectory := newEntry.IsDirectory() + oldPath := oldParent.Child(oldName) newPath := newParent.Child(newName) - oldFsNode := NodeWithId(oldPath.AsInode()) - newFsNode := NodeWithId(newPath.AsInode()) - newDirNode, found := dir.wfs.Server.FindInternalNode(NodeWithId(newParent.AsInode())) + oldFsNode := NodeWithId(oldPath.AsInode(isDirectory)) + newFsNode := NodeWithId(newPath.AsInode(isDirectory)) + newDirNode, found := dir.wfs.Server.FindInternalNode(NodeWithId(newParent.AsInode(true))) var newDir *Dir if found { newDir = newDirNode.(*Dir) @@ -113,17 +115,19 @@ func (dir *Dir) handleRenameResponse(ctx context.Context, resp *filer_pb.StreamR }) // change file handle - inodeId := oldPath.AsInode() - dir.wfs.handlesLock.Lock() - if existingHandle, found := dir.wfs.handles[inodeId]; found && existingHandle != nil { - glog.V(4).Infof("opened file handle %s => %s", oldPath, newPath) - delete(dir.wfs.handles, inodeId) - existingHandle.handle = newPath.AsInode() - existingHandle.f.entry.Name = newName - existingHandle.f.id = newPath.AsInode() - dir.wfs.handles[newPath.AsInode()] = existingHandle + if !isDirectory { + inodeId := oldPath.AsInode(isDirectory) + dir.wfs.handlesLock.Lock() + if existingHandle, found := dir.wfs.handles[inodeId]; found && existingHandle != nil { + glog.V(4).Infof("opened file handle %s => %s", oldPath, newPath) + delete(dir.wfs.handles, inodeId) + existingHandle.handle = newPath.AsInode(isDirectory) + existingHandle.f.entry.Name = newName + existingHandle.f.id = newPath.AsInode(isDirectory) + dir.wfs.handles[newPath.AsInode(isDirectory)] = existingHandle + } + dir.wfs.handlesLock.Unlock() } - dir.wfs.handlesLock.Unlock() } else if resp.EventNotification.OldEntry != nil { // without new entry, only old entry name exists. This is the second step to delete old entry |
