Check for dependencies conflict before deleting a device
This commit is contained in:
@ -23,6 +23,8 @@ pub enum DevicesListError {
|
||||
DeviceNotFound,
|
||||
#[error("Requested device is not validated")]
|
||||
DeviceNotValidated,
|
||||
#[error("Failed to delete device: {0}")]
|
||||
DeleteDeviceFailed(&'static str),
|
||||
#[error("Failed to update relay configuration: {0}")]
|
||||
UpdateRelayFailed(&'static str),
|
||||
#[error("Failed to delete relay: {0}")]
|
||||
@ -178,6 +180,19 @@ impl DevicesList {
|
||||
|
||||
/// Delete a device
|
||||
pub fn delete(&mut self, id: &DeviceId) -> anyhow::Result<()> {
|
||||
// Check for conflicts
|
||||
let device = self
|
||||
.get_single(id)
|
||||
.ok_or(DevicesListError::DeleteDeviceFailed("Device not found!"))?;
|
||||
for r in &device.relays {
|
||||
if !self.relay_get_direct_dependencies(r.id).is_empty() {
|
||||
return Err(DevicesListError::DeleteDeviceFailed(
|
||||
"A relay of this device is required by another relay!",
|
||||
)
|
||||
.into());
|
||||
}
|
||||
}
|
||||
|
||||
let crt_path = AppConfig::get().device_cert_path(id);
|
||||
if crt_path.is_file() {
|
||||
let cert = self.get_cert(id)?;
|
||||
|
Reference in New Issue
Block a user