pub fn decrement_inode_link_count(
        &self,
        inode: Inode,
        count: u32,
    ) -> Result<Option<Inode>, ErrorCode> {
        let mut directories = self.directories.lock().map_err(|_| ErrorCode::Corrupted)?;
        let mut metadata = self.metadata.lock().map_err(|_| ErrorCode::Corrupted)?;
        let db = self.storage.lock().map_err(|_| ErrorCode::Corrupted)?;

        let inode_attrs = metadata
            .get_mut(&inode)
            .ok_or(ErrorCode::InodeDoesNotExist)?;
        inode_attrs.hardlinks -= count;
        inode_attrs.last_metadata_changed = now();
        if inode_attrs.hardlinks == 0 {
            let is_directory = inode_attrs.kind == FileKind::Directory;
            metadata.remove(&inode);
            if is_directory {
                let mut table: Table<Inode, Inode> = db.open_table(PARENTS_TABLE_NAME).unwrap();
                let mut txn = table.begin_write().unwrap();
                txn.remove(&inode).unwrap();
                txn.commit().unwrap();

                if let Some(entries) = directories.remove(&inode) {
                    assert!(entries.is_empty(), "Deleted a non-empty directory inode");
                }
            } else {
                // Only delete file contents if this is not a directory (directories don't have data contents)
                return Ok(Some(inode));
            }
        }

        Ok(None)
    }
// Returns an inode, if that inode's data should be deleted
Returns an inode, if that inode's data should be deleted
Returns an inode if that inode ' s data should be deleted
pub fn decrement_inode_link_count(
        &self,
        inode: Inode,
        count: u32,
    ) -> Result<Option<Inode>, ErrorCode> {
        let mut directories = self.directories.lock().map_err(|_| ErrorCode::Corrupted)?;
        let mut metadata = self.metadata.lock().map_err(|_| ErrorCode::Corrupted)?;
        let db = self.storage.lock().map_err(|_| ErrorCode::Corrupted)?;
        let inode_attrs = metadata
            .get_mut(&inode)
            .ok_or(ErrorCode::InodeDoesNotExist)?;
        inode_attrs.hardlinks -= count;
        inode_attrs.last_metadata_changed = now();
        if inode_attrs.hardlinks == 0 {
            let is_directory = inode_attrs.kind == FileKind::Directory;
            metadata.remove(&inode);
            if is_directory {
                let mut table: Table<Inode, Inode> = db.open_table(PARENTS_TABLE_NAME).unwrap();
                let mut txn = table.begin_write().unwrap();
                txn.remove(&inode).unwrap();
                txn.commit().unwrap();
                if let Some(entries) = directories.remove(&inode) {
                    assert!(entries.is_empty(), "Deleted a non-empty directory inode");
                }
            } else {
                // Only delete file contents if this is not a directory (directories don't have data contents)
                return Ok(Some(inode));
            }
        }
        Ok(None)
    }
pub fn decrement_inode_link_count ( & self , inode : Inode , count : u32 , ) -> Result < Option < Inode > , ErrorCode > { let mut directories = self . directories . lock ( ) . map_err ( | _ | ErrorCode :: Corrupted ) ? ; let mut metadata = self . metadata . lock ( ) . map_err ( | _ | ErrorCode :: Corrupted ) ? ; let db = self . storage . lock ( ) . map_err ( | _ | ErrorCode :: Corrupted ) ? ; let inode_attrs = metadata . get_mut ( & inode ) . ok_or ( ErrorCode :: InodeDoesNotExist ) ? ; inode_attrs . hardlinks -= count ; inode_attrs . last_metadata_changed = now ( ) ; if inode_attrs . hardlinks == 0 { let is_directory = inode_attrs . kind == FileKind :: Directory ; metadata . remove ( & inode ) ; if is_directory { let mut table : Table < Inode , Inode > = db . open_table ( PARENTS_TABLE_NAME ) . unwrap ( ) ; let mut txn = table . begin_write ( ) . unwrap ( ) ; txn . remove ( & inode ) . unwrap ( ) ; txn . commit ( ) . unwrap ( ) ; if let Some ( entries ) = directories . remove ( & inode ) { assert ! ( entries is_empty ( ) " " ) ; } } else { // Only delete file contents if this is not a directory (directories don't have data contents) return Ok ( Some ( inode ) ) ; } } Ok ( None ) }
Returns an inode, if that inode's data should be deleted
Returns an inode if that inode ' s data should be deleted
&self
inode
Inode
count
u32
&self
inode
Inode
count
u32