chore: fix cargo clippy (#174)
This commit is contained in:
parent
fea9bf988a
commit
47883376c1
5 changed files with 26 additions and 32 deletions
|
@ -43,7 +43,7 @@ impl AccessControl {
|
||||||
}
|
}
|
||||||
for rule in raw_rules {
|
for rule in raw_rules {
|
||||||
let parts: Vec<&str> = rule.split('@').collect();
|
let parts: Vec<&str> = rule.split('@').collect();
|
||||||
let create_err = || format!("Invalid auth `{}`", rule).into();
|
let create_err = || format!("Invalid auth `{rule}`").into();
|
||||||
match parts.as_slice() {
|
match parts.as_slice() {
|
||||||
[path, readwrite] => {
|
[path, readwrite] => {
|
||||||
let control = PathControl {
|
let control = PathControl {
|
||||||
|
@ -172,7 +172,7 @@ impl Account {
|
||||||
let user = p[0];
|
let user = p[0];
|
||||||
let pass = p[1];
|
let pass = p[1];
|
||||||
let mut h = Context::new();
|
let mut h = Context::new();
|
||||||
h.consume(format!("{}:{}:{}", user, REALM, pass).as_bytes());
|
h.consume(format!("{user}:{REALM}:{pass}").as_bytes());
|
||||||
Some(Account {
|
Some(Account {
|
||||||
user: user.to_owned(),
|
user: user.to_owned(),
|
||||||
pass: format!("{:x}", h.compute()),
|
pass: format!("{:x}", h.compute()),
|
||||||
|
@ -190,7 +190,7 @@ impl AuthMethod {
|
||||||
pub fn www_auth(&self, stale: bool) -> String {
|
pub fn www_auth(&self, stale: bool) -> String {
|
||||||
match self {
|
match self {
|
||||||
AuthMethod::Basic => {
|
AuthMethod::Basic => {
|
||||||
format!("Basic realm=\"{}\"", REALM)
|
format!("Basic realm=\"{REALM}\"")
|
||||||
}
|
}
|
||||||
AuthMethod::Digest => {
|
AuthMethod::Digest => {
|
||||||
let str_stale = if stale { "stale=true," } else { "" };
|
let str_stale = if stale { "stale=true," } else { "" };
|
||||||
|
|
|
@ -72,7 +72,7 @@ impl FromStr for LogHttp {
|
||||||
let mut elements = vec![];
|
let mut elements = vec![];
|
||||||
let mut is_var = false;
|
let mut is_var = false;
|
||||||
let mut cache = String::new();
|
let mut cache = String::new();
|
||||||
for c in format!("{} ", s).chars() {
|
for c in format!("{s} ").chars() {
|
||||||
if c == '$' {
|
if c == '$' {
|
||||||
if !cache.is_empty() {
|
if !cache.is_empty() {
|
||||||
elements.push(LogElement::Literal(cache.to_string()));
|
elements.push(LogElement::Literal(cache.to_string()));
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -41,7 +41,7 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run() -> BoxResult<()> {
|
async fn run() -> BoxResult<()> {
|
||||||
logger::init().map_err(|e| format!("Failed to init logger, {}", e))?;
|
logger::init().map_err(|e| format!("Failed to init logger, {e}"))?;
|
||||||
let cmd = build_cli();
|
let cmd = build_cli();
|
||||||
let matches = cmd.get_matches();
|
let matches = cmd.get_matches();
|
||||||
if let Some(generator) = matches.get_one::<Shell>("completions") {
|
if let Some(generator) = matches.get_one::<Shell>("completions") {
|
||||||
|
@ -92,7 +92,7 @@ fn serve(
|
||||||
match bind_addr {
|
match bind_addr {
|
||||||
BindAddr::Address(ip) => {
|
BindAddr::Address(ip) => {
|
||||||
let incoming = create_addr_incoming(SocketAddr::new(*ip, port))
|
let incoming = create_addr_incoming(SocketAddr::new(*ip, port))
|
||||||
.map_err(|e| format!("Failed to bind `{}:{}`, {}", ip, port, e))?;
|
.map_err(|e| format!("Failed to bind `{ip}:{port}`, {e}"))?;
|
||||||
match args.tls.as_ref() {
|
match args.tls.as_ref() {
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
Some((certs, key)) => {
|
Some((certs, key)) => {
|
||||||
|
@ -180,7 +180,7 @@ fn print_listening(args: Arc<Args>) -> BoxResult<()> {
|
||||||
}
|
}
|
||||||
if ipv4 || ipv6 {
|
if ipv4 || ipv6 {
|
||||||
let ifaces = if_addrs::get_if_addrs()
|
let ifaces = if_addrs::get_if_addrs()
|
||||||
.map_err(|e| format!("Failed to get local interface addresses: {}", e))?;
|
.map_err(|e| format!("Failed to get local interface addresses: {e}"))?;
|
||||||
for iface in ifaces.into_iter() {
|
for iface in ifaces.into_iter() {
|
||||||
let local_ip = iface.ip();
|
let local_ip = iface.ip();
|
||||||
if ipv4 && local_ip.is_ipv4() {
|
if ipv4 && local_ip.is_ipv4() {
|
||||||
|
@ -212,17 +212,17 @@ fn print_listening(args: Arc<Args>) -> BoxResult<()> {
|
||||||
} else {
|
} else {
|
||||||
let info = urls
|
let info = urls
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| format!(" {}", v))
|
.map(|v| format!(" {v}"))
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
println!("Listening on:\n{}\n", info);
|
println!("Listening on:\n{info}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_err<T>(err: Box<dyn std::error::Error>) -> T {
|
fn handle_err<T>(err: Box<dyn std::error::Error>) -> T {
|
||||||
eprintln!("error: {}", err);
|
eprintln!("error: {err}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -643,7 +643,7 @@ impl Server {
|
||||||
res.headers_mut()
|
res.headers_mut()
|
||||||
.insert(CONTENT_RANGE, content_range.parse().unwrap());
|
.insert(CONTENT_RANGE, content_range.parse().unwrap());
|
||||||
res.headers_mut()
|
res.headers_mut()
|
||||||
.insert(CONTENT_LENGTH, format!("{}", part_size).parse().unwrap());
|
.insert(CONTENT_LENGTH, format!("{part_size}").parse().unwrap());
|
||||||
if head_only {
|
if head_only {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -651,11 +651,11 @@ impl Server {
|
||||||
} else {
|
} else {
|
||||||
*res.status_mut() = StatusCode::RANGE_NOT_SATISFIABLE;
|
*res.status_mut() = StatusCode::RANGE_NOT_SATISFIABLE;
|
||||||
res.headers_mut()
|
res.headers_mut()
|
||||||
.insert(CONTENT_RANGE, format!("bytes */{}", size).parse().unwrap());
|
.insert(CONTENT_RANGE, format!("bytes */{size}").parse().unwrap());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
res.headers_mut()
|
res.headers_mut()
|
||||||
.insert(CONTENT_LENGTH, format!("{}", size).parse().unwrap());
|
.insert(CONTENT_LENGTH, format!("{size}").parse().unwrap());
|
||||||
if head_only {
|
if head_only {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -767,15 +767,14 @@ impl Server {
|
||||||
HeaderValue::from_static("application/xml; charset=utf-8"),
|
HeaderValue::from_static("application/xml; charset=utf-8"),
|
||||||
);
|
);
|
||||||
res.headers_mut()
|
res.headers_mut()
|
||||||
.insert("lock-token", format!("<{}>", token).parse().unwrap());
|
.insert("lock-token", format!("<{token}>").parse().unwrap());
|
||||||
|
|
||||||
*res.body_mut() = Body::from(format!(
|
*res.body_mut() = Body::from(format!(
|
||||||
r#"<?xml version="1.0" encoding="utf-8"?>
|
r#"<?xml version="1.0" encoding="utf-8"?>
|
||||||
<D:prop xmlns:D="DAV:"><D:lockdiscovery><D:activelock>
|
<D:prop xmlns:D="DAV:"><D:lockdiscovery><D:activelock>
|
||||||
<D:locktoken><D:href>{}</D:href></D:locktoken>
|
<D:locktoken><D:href>{token}</D:href></D:locktoken>
|
||||||
<D:lockroot><D:href>{}</D:href></D:lockroot>
|
<D:lockroot><D:href>{req_path}</D:href></D:lockroot>
|
||||||
</D:activelock></D:lockdiscovery></D:prop>"#,
|
</D:activelock></D:lockdiscovery></D:prop>"#
|
||||||
token, req_path
|
|
||||||
));
|
));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -783,14 +782,13 @@ impl Server {
|
||||||
async fn handle_proppatch(&self, req_path: &str, res: &mut Response) -> BoxResult<()> {
|
async fn handle_proppatch(&self, req_path: &str, res: &mut Response) -> BoxResult<()> {
|
||||||
let output = format!(
|
let output = format!(
|
||||||
r#"<D:response>
|
r#"<D:response>
|
||||||
<D:href>{}</D:href>
|
<D:href>{req_path}</D:href>
|
||||||
<D:propstat>
|
<D:propstat>
|
||||||
<D:prop>
|
<D:prop>
|
||||||
</D:prop>
|
</D:prop>
|
||||||
<D:status>HTTP/1.1 403 Forbidden</D:status>
|
<D:status>HTTP/1.1 403 Forbidden</D:status>
|
||||||
</D:propstat>
|
</D:propstat>
|
||||||
</D:response>"#,
|
</D:response>"#
|
||||||
req_path
|
|
||||||
);
|
);
|
||||||
res_multistatus(res, &output);
|
res_multistatus(res, &output);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1021,17 +1019,16 @@ impl PathItem {
|
||||||
match self.path_type {
|
match self.path_type {
|
||||||
PathType::Dir | PathType::SymlinkDir => format!(
|
PathType::Dir | PathType::SymlinkDir => format!(
|
||||||
r#"<D:response>
|
r#"<D:response>
|
||||||
<D:href>{}</D:href>
|
<D:href>{href}</D:href>
|
||||||
<D:propstat>
|
<D:propstat>
|
||||||
<D:prop>
|
<D:prop>
|
||||||
<D:displayname>{}</D:displayname>
|
<D:displayname>{displayname}</D:displayname>
|
||||||
<D:getlastmodified>{}</D:getlastmodified>
|
<D:getlastmodified>{mtime}</D:getlastmodified>
|
||||||
<D:resourcetype><D:collection/></D:resourcetype>
|
<D:resourcetype><D:collection/></D:resourcetype>
|
||||||
</D:prop>
|
</D:prop>
|
||||||
<D:status>HTTP/1.1 200 OK</D:status>
|
<D:status>HTTP/1.1 200 OK</D:status>
|
||||||
</D:propstat>
|
</D:propstat>
|
||||||
</D:response>"#,
|
</D:response>"#
|
||||||
href, displayname, mtime
|
|
||||||
),
|
),
|
||||||
PathType::File | PathType::SymlinkFile => format!(
|
PathType::File | PathType::SymlinkFile => format!(
|
||||||
r#"<D:response>
|
r#"<D:response>
|
||||||
|
@ -1120,9 +1117,8 @@ fn res_multistatus(res: &mut Response, content: &str) {
|
||||||
*res.body_mut() = Body::from(format!(
|
*res.body_mut() = Body::from(format!(
|
||||||
r#"<?xml version="1.0" encoding="utf-8" ?>
|
r#"<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<D:multistatus xmlns:D="DAV:">
|
<D:multistatus xmlns:D="DAV:">
|
||||||
{}
|
{content}
|
||||||
</D:multistatus>"#,
|
</D:multistatus>"#,
|
||||||
content,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1183,9 +1179,7 @@ fn extract_cache_headers(meta: &Metadata) -> Option<(ETag, LastModified)> {
|
||||||
let mtime = meta.modified().ok()?;
|
let mtime = meta.modified().ok()?;
|
||||||
let timestamp = to_timestamp(&mtime);
|
let timestamp = to_timestamp(&mtime);
|
||||||
let size = meta.len();
|
let size = meta.len();
|
||||||
let etag = format!(r#""{}-{}""#, timestamp, size)
|
let etag = format!(r#""{timestamp}-{size}""#).parse::<ETag>().unwrap();
|
||||||
.parse::<ETag>()
|
|
||||||
.unwrap();
|
|
||||||
let last_modified = LastModified::from(mtime);
|
let last_modified = LastModified::from(mtime);
|
||||||
Some((etag, last_modified))
|
Some((etag, last_modified))
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ pub fn load_private_key<T: AsRef<Path>>(
|
||||||
|
|
||||||
// Load and return a single private key.
|
// Load and return a single private key.
|
||||||
let keys = rustls_pemfile::read_all(&mut reader)
|
let keys = rustls_pemfile::read_all(&mut reader)
|
||||||
.map_err(|e| format!("There was a problem with reading private key: {:?}", e))?
|
.map_err(|e| format!("There was a problem with reading private key: {e:?}"))?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find_map(|item| match item {
|
.find_map(|item| match item {
|
||||||
rustls_pemfile::Item::RSAKey(key)
|
rustls_pemfile::Item::RSAKey(key)
|
||||||
|
|
Loading…
Reference in a new issue