Skip to content

Commit

Permalink
fix(backend): fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenclaw900 committed Mar 5, 2022
1 parent 8132326 commit bb5b9cc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/backend/src/page_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub async fn software_handler(
let out =
std::string::String::from_utf8(cmd.args(arg_list).output().unwrap().stdout)
.unwrap()
.replace("", "");
.replace('', "");
let software = systemdata::dpsoftware();
let _send = socket_send
.send(Message::text(SerJson::serialize_json(
Expand Down
21 changes: 9 additions & 12 deletions src/backend/src/socket_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ pub async fn socket_handler(socket: warp::ws::WebSocket) {
if data.is_close() {
break;
}
let data_str;
if let Ok(data_string) = data.to_str() {
data_str = data_string;
let data_str = if let Ok(data_string) = data.to_str() {
data_string
} else {
log::error!("Couldn't convert received data to text");
continue;
}
};
req = if let Ok(json) = DeJson::deserialize_json(data_str) {
json
} else {
Expand Down Expand Up @@ -205,16 +204,15 @@ pub async fn term_handler(socket: warp::ws::WebSocket) {
}
}
data_msg = socket_recv.next() => {
let data;
let lock = cmd_write.read().await;
if let Some(Ok(data_unwrapped)) = data_msg {
data = data_unwrapped;
let data = if let Some(Ok(data_unwrapped)) = data_msg {
data_unwrapped
} else {
let _write = (*cmd_write.read().await)
.pty()
.write_all("exit\n".as_bytes());
continue;
}
};
if data.is_text() && data.to_str().unwrap().get(..4) == Some("size") {
let json: TTYSize =
DeJson::deserialize_json(&data.to_str().unwrap()[4..]).unwrap();
Expand Down Expand Up @@ -267,13 +265,12 @@ pub async fn file_handler(mut socket: warp::ws::WebSocket) {
}
continue;
}
let data_str;
if let Ok(data_string) = data.to_str() {
data_str = data_string;
let data_str = if let Ok(data_string) = data.to_str() {
data_string
} else {
log::error!("Couldn't convert received data to text");
continue;
}
};
req = if let Ok(json) = DeJson::deserialize_json(data_str) {
json
} else {
Expand Down
42 changes: 19 additions & 23 deletions src/backend/src/systemdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,23 @@ pub async fn processes() -> Vec<shared::ProcessData> {
match element {
Ok(mut unwrapped) => {
// Everything could fail if the process terminates, if so skip the process
let name;
match unwrapped.name() {
Ok(unwrapped_name) => name = unwrapped_name,
let name = match unwrapped.name() {
Ok(unwrapped_name) => unwrapped_name,
Err(_) => continue,
}
};
if unwrapped.cmdline().unwrap().is_none() {
continue;
}
let status: String;
match unwrapped.status().unwrap() {
let status = match unwrapped.status().unwrap() {
// The processes that are running show up as sleeping, for some reason
process::Status::Sleeping => status = "running".to_string(),
process::Status::Idle => status = "idle".to_string(),
process::Status::Stopped => status = "stopped".to_string(),
process::Status::Zombie => status = "zombie".to_string(),
process::Status::Dead => status = "dead".to_string(),
_ => status = String::new(),
process::Status::Sleeping => "running",
process::Status::Idle => "idle",
process::Status::Stopped => "stopped",
process::Status::Zombie => "zombie",
process::Status::Dead => "dead",
_ => "",
}
.to_string();
process_list.push(shared::ProcessData {
pid: unwrapped.pid(),
name,
Expand Down Expand Up @@ -154,15 +153,13 @@ pub fn dpsoftware() -> (Vec<shared::DPSoftwareData>, Vec<shared::DPSoftwareData>
.nth(4)
.unwrap()
.trim_start_matches("Free software ID(s): ");
let free_list: Vec<i16>;
if &free[..4] == "None" {
free_list = Vec::new();
let free_list = if &free[..4] == "None" {
Vec::new()
} else {
free_list = free
.split(' ')
free.split(' ')
.map(|id| id.parse::<i16>().unwrap())
.collect();
}
.collect()
};
let out = Command::new("/boot/dietpi/dietpi-software")
.arg("list")
.output()
Expand Down Expand Up @@ -374,9 +371,8 @@ pub fn browser_dir(path: &std::path::Path) -> Vec<shared::BrowserDirData> {
subtype = String::new();
prettytype = "Directory".to_string();
} else {
let buf;
if let Ok(val) = fs::read(path) {
buf = val;
let buf = if let Ok(val) = fs::read(path) {
val
} else {
log::error!("Could not read directory");
return vec![shared::BrowserDirData {
Expand All @@ -387,7 +383,7 @@ pub fn browser_dir(path: &std::path::Path) -> Vec<shared::BrowserDirData> {
prettytype: "Could not read directory".to_string(),
size: 0,
}];
}
};
if let Some(infertype) = infer::get(&buf) {
subtype = infertype.mime_type().split_once('/').unwrap().1.to_string();
maintype = {
Expand Down

0 comments on commit bb5b9cc

Please sign in to comment.