File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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,9 +182,15 @@ 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+ // replace the old path with the new one
183186 let idx = self . by_path . remove ( Pathish :: new ( oldpath) ) . unwrap ( ) ;
184187 self . table [ idx] . path = Some ( newpath. clone ( ) ) ;
185- self . by_path . insert ( newpath, idx) ; // this can replace a path with a new inode
188+ let prev = self . by_path . insert ( newpath, idx) ; // this can replace a path with a new inode
189+
190+ // unlink the new path from the previous inode holding it
191+ if let Some ( prev) = prev {
192+ self . table [ prev] . path = None ;
193+ }
186194 }
187195
188196 /// Remove the path->inode mapping for a given path, but keep the inode around.
You can’t perform that action at this time.
0 commit comments