Skip to content

Commit

Permalink
fix(manager): ignore NotADirectory error when uninstalling services
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin authored and joshuef committed Jun 7, 2024
1 parent ec679b5 commit 5e673b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
5 changes: 4 additions & 1 deletion sn_node_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,16 @@ impl<T: ServiceStateActions + Send> ServiceManager<T> {
}
Err(err) => match err {
ServiceError::ServiceRemovedManually(name) => {
warn!("The user appears to have removed the {name} service manually",);
warn!("The user appears to have removed the {name} service manually. Skipping the error.",);
// The user has deleted the service definition file, which the service manager
// crate treats as an error. We then return our own error type, which allows us
// to handle it here and just proceed with removing the service from the
// registry.
println!("The user appears to have removed the {name} service manually");
}
ServiceError::ServiceDoesNotExists(name) => {
warn!("The service {name} has most probably been removed already, it does not exists. Skipping the error.");
}
_ => {
error!("Error uninstalling the service: {err}");
return Err(err.into());
Expand Down
21 changes: 14 additions & 7 deletions sn_service_management/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,26 @@ impl ServiceControl for ServiceController {
}
match manager.uninstall(ServiceUninstallCtx { label }) {
Ok(()) => Ok(()),
Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => {
Err(err) => {
if std::io::ErrorKind::NotFound == err.kind() {
error!("Error while uninstall service, service file might have been removed manually: {service_name}");
// In this case the user has removed the service definition file manually,
// which the service manager crate treats as an error. We can propagate the
// it to the caller and they can decide how to handle it.
Err(Error::ServiceRemovedManually(service_name.to_string()))
} else if err.raw_os_error() == Some(267) {
// This requires the unstable io_error_more feature, use raw code for now
// else if err.kind() == std::io::ErrorKind::NotADirectory {}

// This happens on windows when the service has been already cleared, but was not updated
// in the registry. Happens when the Service application (in windows) is open while calling
// 'remove' or 'reset'.
Err(Error::ServiceDoesNotExists(service_name.to_string()))
} else {
error!("Error while uninstalling service: {err:?}");
Err(err.into())
}
_ => {
error!("Error while uninstalling service: {e:?}");
Err(e.into())
}
},
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions sn_service_management/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub enum Error {
RpcRecordAddressError(String),
#[error("Could not find process at '{0}'")]
ServiceProcessNotFound(String),
#[error("The service '{0}' does not exists and cannot be removed.")]
ServiceDoesNotExists(String),
#[error("The user may have removed the '{0}' service outwith the node manager")]
ServiceRemovedManually(String),
#[error("Failed to create service user account")]
Expand Down

0 comments on commit 5e673b6

Please sign in to comment.