🚨 refactor: fix some Clippy lints

main
_ 2020-12-18 23:41:52 +00:00
parent d03c1a5476
commit 72b3b33206
2 changed files with 36 additions and 35 deletions

View File

@ -181,39 +181,39 @@ async fn serve_api (
{ {
use Response::*; use Response::*;
match prefix_match ("/v1/dir/", path) { // API versioning will be major-only, so I'll keep adding stuff to v1
None => (), // until I need to deprecate or break something.
Some (path) => {
let encoded_path = &path [0..]; if let Some (path) = prefix_match ("/v1/dir/", path) {
let encoded_path = &path [0..];
let path_s = percent_decode (encoded_path.as_bytes ()).decode_utf8 ().map_err (FileServerError::PathNotUtf8)?;
let path = Path::new (&*path_s); let path_s = percent_decode (encoded_path.as_bytes ()).decode_utf8 ().map_err (FileServerError::PathNotUtf8)?;
let path = Path::new (&*path_s);
let full_path = root.join (path);
let full_path = root.join (path);
debug! ("full_path = {:?}", full_path);
debug! ("full_path = {:?}", full_path);
if let Some (hidden_path) = hidden_path {
if full_path == hidden_path { if let Some (hidden_path) = hidden_path {
return Ok (Forbidden); if full_path == hidden_path {
} return Ok (Forbidden);
} }
}
return if let Ok (dir) = read_dir (&full_path).await {
serve_dir ( return if let Ok (dir) = read_dir (&full_path).await {
&path_s, serve_dir (
path, &path_s,
dir, path,
full_path, dir,
&uri, full_path,
OutputFormat::Json &uri,
) OutputFormat::Json
} )
else { }
Ok (NotFound) else {
}; Ok (NotFound)
}, };
}; }
Ok (NotFound) Ok (NotFound)
} }

View File

@ -17,7 +17,7 @@ pub struct InstanceMetrics {
pub machine_id: Option <String>, pub machine_id: Option <String>,
// Git version that ptth_server was built from (unimplemented) // Git version that ptth_server was built from (unimplemented)
pub _git_version: Option <String>, pub git_version: Option <String>,
// User-assigned and human-readable name for this server. // User-assigned and human-readable name for this server.
// Must be unique within a relay. // Must be unique within a relay.
@ -37,7 +37,7 @@ fn get_machine_id () -> Option <String> {
io::Read, io::Read,
}; };
let mut buf = vec! [0u8; 1024]; let mut buf = vec! [0; 1024];
let mut f = File::open ("/etc/machine-id").ok ()?; let mut f = File::open ("/etc/machine-id").ok ()?;
let bytes_read = f.read (&mut buf).ok ()?; let bytes_read = f.read (&mut buf).ok ()?;
@ -50,11 +50,12 @@ fn get_machine_id () -> Option <String> {
} }
impl InstanceMetrics { impl InstanceMetrics {
#[must_use]
pub fn new (server_name: String) -> Self pub fn new (server_name: String) -> Self
{ {
Self { Self {
machine_id: get_machine_id (), machine_id: get_machine_id (),
_git_version: None, git_version: None,
server_name, server_name,
instance_id: ulid::Ulid::new (), instance_id: ulid::Ulid::new (),
startup_utc: Utc::now (), startup_utc: Utc::now (),