Skip to content

Commit 6e1e41a

Browse files
committed
unlink the new path from the replaced inode in rename
1 parent ee9d91d commit 6e1e41a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/inode_table.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ impl InodeTable {
165165
lookups = entry.lookups;
166166
if lookups == 0 {
167167
delete = true;
168-
self.by_path.remove(entry.path.as_ref().unwrap());
168+
if let Some(path) = entry.path.as_ref() {
169+
self.by_path.remove(path);
170+
}
169171
}
170172
}
171173

@@ -180,6 +182,12 @@ impl InodeTable {
180182
/// Change an inode's path to a different one, without changing the inode number.
181183
/// Lookup counts remain unchanged, even if this is replacing another file.
182184
pub fn rename(&mut self, oldpath: &Path, newpath: Arc<PathBuf>) {
185+
// unlink the new path from the previous inode holding it
186+
// otherwise, when kernel signals to forget the replaced inode, the path is removed from the by_path table
187+
if let Some(dst) = self.by_path.remove(Pathish::new(&newpath)) {
188+
self.table[dst].path = None;
189+
}
190+
183191
let idx = self.by_path.remove(Pathish::new(oldpath)).unwrap();
184192
self.table[idx].path = Some(newpath.clone());
185193
self.by_path.insert(newpath, idx); // this can replace a path with a new inode

0 commit comments

Comments
 (0)