Skip to content

Commit

Permalink
Implement volume update, mount state change, and error handling in Vo…
Browse files Browse the repository at this point in the history
…lumeManagerActor
  • Loading branch information
jamiepine committed Nov 3, 2024
1 parent e9ce227 commit ad18bbe
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions core/src/volume/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ impl VolumeManagerActor {
.volumes
.remove(&volume.generate_fingerprint(current_device_pub_id.clone()));
}
VolumeEvent::VolumeUpdated { old, new } => todo!(),
VolumeEvent::VolumeUpdated { old: _, new } => {
self.state
.write()
.await
.volumes
.insert(new.generate_fingerprint(current_device_pub_id.clone()), new);
}
VolumeEvent::VolumeSpeedTested {
id,
read_speed,
Expand All @@ -142,8 +148,24 @@ impl VolumeManagerActor {
.unwrap()
.write_speed_mbps = Some(write_speed);
}
VolumeEvent::VolumeMountChanged { id, is_mounted } => todo!(),
VolumeEvent::VolumeError { id, error } => todo!(),
VolumeEvent::VolumeMountChanged { id, is_mounted } => {
self.state
.write()
.await
.volumes
.get_mut(&id)
.unwrap()
.is_mounted = is_mounted;
}
VolumeEvent::VolumeError { id, error } => {
self.state
.write()
.await
.volumes
.get_mut(&id)
.unwrap()
.error_status = Some(error);
}
}
}
warn!("Volume event monitoring ended");
Expand Down Expand Up @@ -520,12 +542,6 @@ impl VolumeManagerActor {
// Call the platform-specific unmount function
super::os::unmount_volume(&volume.mount_point).await?;

// If unmount succeeded, update our state
let mut state = self.state.write().await;
if let Some(vol) = state.volumes.get_mut(&volume_fingerprint) {
vol.is_mounted = false;
}

// Emit unmount event
if let Some(pub_id) = volume.pub_id {
let _ = self.event_tx.send(VolumeEvent::VolumeMountChanged {
Expand Down

0 comments on commit ad18bbe

Please sign in to comment.