backport: fix clippy warnings

This commit is contained in:
jb-alvarado 2023-10-08 20:46:27 +02:00
parent 0808fb29ab
commit 05ab9aac71

View File

@ -296,45 +296,56 @@ pub async fn media_info(
post_request(conn, id, json_obj).await post_request(conn, id, json_obj).await
} }
async fn execute_systemd(
conn: &Pool<Sqlite>,
id: i32,
command: &ServiceCmd,
) -> Result<String, ServiceError> {
let system_d = SystemD::new(conn, id).await?;
match command {
ServiceCmd::Enable => system_d.enable(),
ServiceCmd::Disable => system_d.disable(),
ServiceCmd::Start => system_d.start(),
ServiceCmd::Stop => system_d.stop(),
ServiceCmd::Restart => system_d.restart(),
ServiceCmd::Status => system_d.status().await,
}
}
pub async fn control_service( pub async fn control_service(
conn: &Pool<Sqlite>, conn: &Pool<Sqlite>,
id: i32, id: i32,
command: &ServiceCmd, command: &ServiceCmd,
engine: Option<web::Data<ProcessControl>>, engine: Option<web::Data<ProcessControl>>,
) -> Result<String, ServiceError> { ) -> Result<String, ServiceError> {
if engine.is_some() && engine.as_ref().unwrap().piggyback.load(Ordering::SeqCst) { if let Some(en) = engine {
match command { if en.piggyback.load(Ordering::SeqCst) {
ServiceCmd::Start => engine.unwrap().start().await, match command {
ServiceCmd::Stop => { ServiceCmd::Start => en.start().await,
if control_state(conn, id, "stop_all").await.is_ok() { ServiceCmd::Stop => {
engine.unwrap().stop().await if control_state(conn, id, "stop_all").await.is_ok() {
} else { en.stop().await
Err(ServiceError::NoContent("Nothing to stop".to_string())) } else {
Err(ServiceError::NoContent("Nothing to stop".to_string()))
}
} }
} ServiceCmd::Restart => {
ServiceCmd::Restart => { if control_state(conn, id, "stop_all").await.is_ok() {
if control_state(conn, id, "stop_all").await.is_ok() { en.restart().await
engine.unwrap().restart().await } else {
} else { Err(ServiceError::NoContent("Nothing to restart".to_string()))
Err(ServiceError::NoContent("Nothing to stop".to_string())) }
} }
ServiceCmd::Status => en.status(),
_ => Err(ServiceError::Conflict(
"Engine runs in piggyback mode, in this mode this command is not allowed."
.to_string(),
)),
} }
ServiceCmd::Status => engine.unwrap().status(), } else {
_ => Err(ServiceError::Conflict( execute_systemd(conn, id, command).await
"Engine runs in piggyback mode, in this mode this command is not allowed."
.to_string(),
)),
} }
} else { } else {
let system_d = SystemD::new(conn, id).await?; execute_systemd(conn, id, command).await
match command {
ServiceCmd::Enable => system_d.enable(),
ServiceCmd::Disable => system_d.disable(),
ServiceCmd::Start => system_d.start(),
ServiceCmd::Stop => system_d.stop(),
ServiceCmd::Restart => system_d.restart(),
ServiceCmd::Status => system_d.status().await,
}
} }
} }