avoid some clippy warnings
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use std::hash::BuildHasher;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
@ -119,7 +120,7 @@ impl tower_service::Service<Request<Body>> for ApiService {
|
||||
let path = req.uri().path().to_owned();
|
||||
let method = req.method().clone();
|
||||
|
||||
let peer = self.peer.clone();
|
||||
let peer = self.peer;
|
||||
Pin::from(handle_request(self.api_config.clone(), req))
|
||||
.map(move |result| match result {
|
||||
Ok(res) => {
|
||||
@ -144,11 +145,11 @@ impl tower_service::Service<Request<Body>> for ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_request_parameters_async(
|
||||
fn get_request_parameters_async<S: 'static + BuildHasher + Send>(
|
||||
info: &'static ApiMethod,
|
||||
parts: Parts,
|
||||
req_body: Body,
|
||||
uri_param: HashMap<String, String>,
|
||||
uri_param: HashMap<String, String, S>,
|
||||
) -> Box<dyn Future<Output = Result<Value, failure::Error>> + Send>
|
||||
{
|
||||
let mut is_json = false;
|
||||
@ -162,7 +163,7 @@ fn get_request_parameters_async(
|
||||
is_json = true;
|
||||
}
|
||||
_ => {
|
||||
return Box::new(future::err(http_err!(BAD_REQUEST, format!("unsupported content type"))));
|
||||
return Box::new(future::err(http_err!(BAD_REQUEST, "unsupported content type".to_string())));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,7 +175,7 @@ fn get_request_parameters_async(
|
||||
acc.extend_from_slice(&*chunk);
|
||||
Ok(acc)
|
||||
} else {
|
||||
Err(http_err!(BAD_REQUEST, format!("Request body too large")))
|
||||
Err(http_err!(BAD_REQUEST, "Request body too large".to_string()))
|
||||
}
|
||||
})
|
||||
.and_then(move |body| async move {
|
||||
@ -195,11 +196,10 @@ fn get_request_parameters_async(
|
||||
|
||||
let mut param_list: Vec<(String, String)> = vec![];
|
||||
|
||||
if utf8.len() > 0 {
|
||||
if !utf8.is_empty() {
|
||||
for (k, v) in form_urlencoded::parse(utf8.as_bytes()).into_owned() {
|
||||
param_list.push((k, v));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if let Some(query_str) = parts.uri.query() {
|
||||
@ -260,13 +260,13 @@ fn proxy_protected_request(
|
||||
})
|
||||
}
|
||||
|
||||
pub fn handle_sync_api_request<Env: RpcEnvironment>(
|
||||
pub fn handle_sync_api_request<Env: RpcEnvironment, S: 'static + BuildHasher + Send>(
|
||||
mut rpcenv: Env,
|
||||
info: &'static ApiMethod,
|
||||
formatter: &'static OutputFormatter,
|
||||
parts: Parts,
|
||||
req_body: Body,
|
||||
uri_param: HashMap<String, String>,
|
||||
uri_param: HashMap<String, String, S>,
|
||||
) -> BoxFut
|
||||
{
|
||||
let params = get_request_parameters_async(info, parts, req_body, uri_param);
|
||||
@ -339,7 +339,7 @@ pub fn handle_async_api_request<Env: RpcEnvironment>(
|
||||
match (info.handler)(parts, req_body, params, info, Box::new(rpcenv)) {
|
||||
Ok(future) => future,
|
||||
Err(err) => {
|
||||
let resp = (formatter.format_error)(Error::from(err));
|
||||
let resp = (formatter.format_error)(err);
|
||||
Box::new(future::ok(resp))
|
||||
}
|
||||
}
|
||||
@ -348,9 +348,9 @@ pub fn handle_async_api_request<Env: RpcEnvironment>(
|
||||
fn get_index(username: Option<String>, token: Option<String>) -> Response<Body> {
|
||||
|
||||
let nodename = proxmox::tools::nodename();
|
||||
let username = username.unwrap_or(String::from(""));
|
||||
let username = username.unwrap_or_else(|| String::from(""));
|
||||
|
||||
let token = token.unwrap_or(String::from(""));
|
||||
let token = token.unwrap_or_else(|| String::from(""));
|
||||
|
||||
let setup = json!({
|
||||
"Setup": { "auth_cookie_name": "PBSAuthCookie" },
|
||||
@ -614,7 +614,7 @@ pub fn handle_request(api: Arc<ApiConfig>, req: Request<Body>) -> BoxFut {
|
||||
// not Auth required for accessing files!
|
||||
|
||||
if method != hyper::Method::GET {
|
||||
return Box::new(future::err(http_err!(BAD_REQUEST, format!("Unsupported method"))));
|
||||
return Box::new(future::err(http_err!(BAD_REQUEST, "Unsupported method".to_string())));
|
||||
}
|
||||
|
||||
if comp_len == 0 {
|
||||
|
@ -22,7 +22,6 @@ pub struct ServerState {
|
||||
pub reload_request: bool,
|
||||
}
|
||||
|
||||
|
||||
lazy_static! {
|
||||
static ref SERVER_STATE: Mutex<ServerState> = Mutex::new(ServerState {
|
||||
mode: ServerMode::Normal,
|
||||
@ -69,11 +68,7 @@ pub fn server_state_init() -> Result<(), Error> {
|
||||
pub fn is_reload_request() -> bool {
|
||||
let data = SERVER_STATE.lock().unwrap();
|
||||
|
||||
if data.mode == ServerMode::Shutdown && data.reload_request {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
data.mode == ServerMode::Shutdown && data.reload_request
|
||||
}
|
||||
|
||||
pub fn server_shutdown() {
|
||||
|
@ -43,16 +43,10 @@ lazy_static! {
|
||||
pub fn worker_is_active(upid: &UPID) -> bool {
|
||||
|
||||
if (upid.pid == *MY_PID) && (upid.pstart == *MY_PID_PSTART) {
|
||||
if WORKER_TASK_LIST.lock().unwrap().contains_key(&upid.task_id) {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
WORKER_TASK_LIST.lock().unwrap().contains_key(&upid.task_id)
|
||||
} else {
|
||||
match proxmox::sys::linux::procfs::check_process_running_pstart(upid.pid, upid.pstart) {
|
||||
Some(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
use proxmox::sys::linux::procfs;
|
||||
procfs::check_process_running_pstart(upid.pid, upid.pstart).is_some()
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,17 +57,17 @@ pub fn create_task_control_socket() -> Result<(), Error> {
|
||||
|
||||
let control_future = super::create_control_socket(socketname, |param| {
|
||||
let param = param.as_object()
|
||||
.ok_or(format_err!("unable to parse parameters (expected json object)"))?;
|
||||
.ok_or_else(|| format_err!("unable to parse parameters (expected json object)"))?;
|
||||
if param.keys().count() != 2 { bail!("wrong number of parameters"); }
|
||||
|
||||
let command = param.get("command")
|
||||
.ok_or(format_err!("unable to parse parameters (missing command)"))?;
|
||||
.ok_or_else(|| format_err!("unable to parse parameters (missing command)"))?;
|
||||
|
||||
// this is the only command for now
|
||||
if command != "abort-task" { bail!("got unknown command '{}'", command); }
|
||||
|
||||
let upid_str = param["upid"].as_str()
|
||||
.ok_or(format_err!("unable to parse parameters (missing upid)"))?;
|
||||
.ok_or_else(|| format_err!("unable to parse parameters (missing upid)"))?;
|
||||
|
||||
let upid = upid_str.parse::<UPID>()?;
|
||||
|
||||
@ -244,7 +238,8 @@ fn update_active_workers(new_upid: Option<&UPID>) -> Result<Vec<TaskListInfo>, E
|
||||
match state {
|
||||
None => {
|
||||
println!("Detected stoped UPID {}", upid_str);
|
||||
let status = upid_read_status(&upid).unwrap_or(String::from("unknown"));
|
||||
let status = upid_read_status(&upid)
|
||||
.unwrap_or_else(|_| String::from("unknown"));
|
||||
finish_list.push(TaskListInfo {
|
||||
upid, upid_str, state: Some((Local::now().timestamp(), status))
|
||||
});
|
||||
|
Reference in New Issue
Block a user