Repository: bevyengine/bevy
File: crates/bevy_asset/src/processor/mod.rs (Rust)

Code before:
        new_info.processed_info = info.processed_info;
        new_info.status = info.status;
        // Ensure things waiting on the new path are informed of the status of this asset
        if let Some(status) = new_info.status {
            new_info.status_sender.broadcast(status).await.unwrap();
        }
        let dependents = new_info.dependents.iter().cloned().collect::<Vec<_>>();
        // Queue the asset for a reprocess check, in case it needs new meta.
        let _ = new_task_sender
            .send((new.source().clone_owned(), new.path().to_owned()))
            .await;
        for dependent in dependents {
            // Queue dependents for reprocessing because they might have been waiting for this asset.
            let _ = new_task_sender
                .send((
                    dependent.source().clone_owned(),
                    dependent.path().to_owned(),
                ))
                .await;
        }

        Some((
            info.file_transaction_lock,
            new_info.file_transaction_lock.clone(),
        ))
    }

    fn clear_dependencies(&mut self, asset_path: &AssetPath<'static>, removed_info: ProcessedInfo) {
        for old_load_dep in removed_info.process_dependencies {
            if let Some(info) = self.infos.get_mut(&old_load_dep.path) {
                info.dependents.remove(asset_path);
            } else if let Some(dependents) =
                self.non_existent_dependents.get_mut(&old_load_dep.path)
            {
                dependents.remove(asset_path);
            }
        }
    }
}

/// The current state of the [`AssetProcessor`].
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum ProcessorState {
    /// The processor is still initializing, which involves scanning the current asset folders,
    /// constructing an in-memory view of the asset space, recovering from previous errors / crashes,
    /// and cleaning up old / unused assets.
    Initializing,
    /// The processor is currently processing assets.
    Processing,
    /// The processor has finished processing all valid assets and reporting invalid assets.
    Finished,

Review comment (suggestion):
The old path’s lock is not a `clone` because theoretically there should be no other threads that want it since it has been removed, but the new path’s lock is a `clone` because there might be other threads currently using it (if it’s an existing path) right?

(also this was a nice catch!)

Code after:
            .unwrap();
        let new_info = self.get_or_insert(new.clone());
        new_info.processed_info = info.processed_info;
        new_info.status = info.status;
        // Ensure things waiting on the new path are informed of the status of this asset
        if let Some(status) = new_info.status {
            new_info.status_sender.broadcast(status).await.unwrap();
        }
        let dependents = new_info.dependents.iter().cloned().collect::<Vec<_>>();
        // Queue the asset for a reprocess check, in case it needs new meta.
        let _ = new_task_sender
            .send((new.source().clone_owned(), new.path().to_owned()))
            .await;
        for dependent in dependents {
            // Queue dependents for reprocessing because they might have been waiting for this asset.
            let _ = new_task_sender
                .send((
                    dependent.source().clone_owned(),
                    dependent.path().to_owned(),
                ))
                .await;
        }

        Some((
            info.file_transaction_lock,
            new_info.file_transaction_lock.clone(),
        ))
    }

    fn clear_dependencies(&mut self, asset_path: &AssetPath<'static>, removed_info: ProcessedInfo) {
        for old_load_dep in removed_info.process_dependencies {
            if let Some(info) = self.infos.get_mut(&old_load_dep.path) {
                info.dependents.remove(asset_path);
            } else if let Some(dependents) =
                self.non_existent_dependents.get_mut(&old_load_dep.path)
            {
                dependents.remove(asset_path);
            }
        }
    }
}

/// The current state of the [`AssetProcessor`].
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum ProcessorState {
    /// The processor is still initializing, which involves scanning the current asset folders,
    /// constructing an in-memory view of the asset space, recovering from previous errors / crashes,
    /// and cleaning up old / unused assets.
    Initializing,
    /// The processor is currently processing assets.
    Processing,