chore: apply clippy lints

This commit is contained in:
Aravinth Manivannan 2022-11-15 18:09:34 +05:30
parent b07f076634
commit 1e0fa7279f
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
10 changed files with 20 additions and 29 deletions

View File

@ -18,7 +18,7 @@ use std::process::Command;
fn main() { fn main() {
let output = Command::new("git") let output = Command::new("git")
.args(&["rev-parse", "HEAD"]) .args(["rev-parse", "HEAD"])
.output() .output()
.expect("error in git command, is git installed?"); .expect("error in git command, is git installed?");
let git_hash = String::from_utf8(output.stdout).unwrap(); let git_hash = String::from_utf8(output.stdout).unwrap();

View File

@ -55,7 +55,7 @@ impl Ctx {
self.db.add_site(&db_site).await?; self.db.add_site(&db_site).await?;
let page = Page::from_site(&self.settings, db_site); let page = Page::from_site(&self.settings, db_site);
page.update(&page.branch)?; page.update(&page.branch)?;
if let Some(config) = page_config::Config::load(&page.path, &page.branch) { if let Some(_config) = page_config::Config::load(&page.path, &page.branch) {
unimplemented!(); unimplemented!();
} }
Ok(page) Ok(page)
@ -78,7 +78,7 @@ impl Ctx {
.unwrap(); .unwrap();
} }
rx.await.unwrap()?; rx.await.unwrap()?;
if let Some(config) = page_config::Config::load(&page.path, &page.branch) { if let Some(_config) = page_config::Config::load(&page.path, &page.branch) {
unimplemented!(); unimplemented!();
} }
Ok(()) Ok(())

View File

@ -23,7 +23,6 @@ use sqlx::types::time::OffsetDateTime;
use sqlx::ConnectOptions; use sqlx::ConnectOptions;
use sqlx::PgPool; use sqlx::PgPool;
use tracing::error; use tracing::error;
use url::quirks::hostname;
use crate::errors::*; use crate::errors::*;

View File

@ -16,7 +16,6 @@
*/ */
use actix_web::{web, HttpResponse, Responder}; use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::sync::oneshot;
use crate::errors::*; use crate::errors::*;
use crate::page::Page; use crate::page::Page;

View File

@ -187,12 +187,10 @@ fn read_file_inner(
} }
fn file_not_found(e: git2::Error) -> ServiceError { fn file_not_found(e: git2::Error) -> ServiceError {
if e.code() == ErrorCode::NotFound { if e.code() == ErrorCode::NotFound && e.class() == ErrorClass::Tree {
if e.class() == ErrorClass::Tree { return ServiceError::FileNotFound;
return ServiceError::FileNotFound;
}
} }
return e.into(); e.into()
} }
let entry = tree.get_path(Path::new(path)).map_err(file_not_found)?; let entry = tree.get_path(Path::new(path)).map_err(file_not_found)?;

View File

@ -102,9 +102,9 @@ impl Config {
branch: &str, branch: &str,
policies: &'a [Policy<'a>], policies: &'a [Policy<'a>],
) -> Option<&'a Policy<'a>> { ) -> Option<&'a Policy<'a>> {
let repo = git2::Repository::open(&repo_path).unwrap(); let repo = git2::Repository::open(repo_path).unwrap();
let branch = repo.find_branch(&branch, git2::BranchType::Local).unwrap(); let branch = repo.find_branch(branch, git2::BranchType::Local).unwrap();
// let tree = head.peel_to_tree().unwrap(); // let tree = head.peel_to_tree().unwrap();
let branch = branch.into_reference(); let branch = branch.into_reference();
let tree = branch.peel_to_tree().unwrap(); let tree = branch.peel_to_tree().unwrap();
@ -114,10 +114,7 @@ impl Config {
if let Some(name) = x.name() { if let Some(name) = x.name() {
if policies.iter().any(|p| p.rel_path == name) { if policies.iter().any(|p| p.rel_path == name) {
let mode: GitFileMode = x.into(); let mode: GitFileMode = x.into();
match mode { matches!(mode, GitFileMode::Executable | GitFileMode::Regular)
GitFileMode::Executable | GitFileMode::Regular => true,
_ => false,
}
} else { } else {
false false
} }
@ -142,7 +139,7 @@ impl Config {
} }
fn load_json(c: &str) -> Config { fn load_json(c: &str) -> Config {
serde_json::from_str(&c).unwrap() serde_json::from_str(c).unwrap()
} }
} }

View File

@ -104,7 +104,7 @@ pub fn context(s: &Settings) -> Context {
ctx ctx
} }
pub fn auth_ctx(username: Option<&str>, s: &Settings) -> Context { pub fn auth_ctx(_username: Option<&str>, s: &Settings) -> Context {
let mut ctx = Context::new(); let mut ctx = Context::new();
let footer = Footer::new(s); let footer = Footer::new(s);
ctx.insert("footer", &footer); ctx.insert("footer", &footer);

View File

@ -38,9 +38,9 @@ impl<'a> Preview<'a> {
} }
pub fn extract(&self, hostname: &'a str) -> Option<&'a str> { pub fn extract(&self, hostname: &'a str) -> Option<&'a str> {
if !hostname.contains(&self.delimiter) if !hostname.contains(self.delimiter)
|| !hostname.contains(&self.prefix) || !hostname.contains(self.prefix)
|| !hostname.contains(&self.base) || !hostname.contains(self.base)
{ {
return None; return None;
} }

View File

@ -53,8 +53,8 @@ async fn index(req: HttpRequest, ctx: AppCtx) -> ServiceResult<impl Responder> {
if host.contains(&ctx.settings.page.base_domain) { if host.contains(&ctx.settings.page.base_domain) {
let extractor = crate::preview::Preview::new(&ctx); let extractor = crate::preview::Preview::new(&ctx);
if let Some(preview_branch) = extractor.extract(host) { if let Some(preview_branch) = extractor.extract(host) {
let res = if ctx.db.hostname_exists(&host).await? { let res = if ctx.db.hostname_exists(host).await? {
let path = crate::utils::get_website_path(&ctx.settings, &host); let path = crate::utils::get_website_path(&ctx.settings, host);
let content = let content =
crate::git::read_preview_file(&path, preview_branch, req.uri().path())?; crate::git::read_preview_file(&path, preview_branch, req.uri().path())?;
let mime = if let Some(mime) = content.mime.first_raw() { let mime = if let Some(mime) = content.mime.first_raw() {
@ -75,7 +75,7 @@ async fn index(req: HttpRequest, ctx: AppCtx) -> ServiceResult<impl Responder> {
// TODO: custom domains. // TODO: custom domains.
if ctx.db.hostname_exists(host).await? { if ctx.db.hostname_exists(host).await? {
let path = crate::utils::get_website_path(&ctx.settings, &host); let path = crate::utils::get_website_path(&ctx.settings, host);
let content = crate::git::read_file(&path, req.uri().path())?; let content = crate::git::read_file(&path, req.uri().path())?;
let mime = if let Some(mime) = content.mime.first_raw() { let mime = if let Some(mime) = content.mime.first_raw() {
mime mime

View File

@ -16,22 +16,20 @@
*/ */
use std::env; use std::env;
use std::path::Path; use std::path::Path;
use std::sync::Arc;
use config::{Config, ConfigError, Environment, File}; use config::{Config, ConfigError, Environment, File};
use derive_more::Display; use derive_more::Display;
#[cfg(not(test))] #[cfg(not(test))]
use tracing::{error, warn}; use tracing::warn;
#[cfg(test)] #[cfg(test)]
use std::{println as warn, println as error}; use std::println as warn;
use serde::Deserialize; use serde::Deserialize;
use serde::Serialize; use serde::Serialize;
use url::Url; use url::Url;
use crate::errors::*; use crate::errors::*;
use crate::page::Page;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Server { pub struct Server {
@ -178,7 +176,7 @@ impl Settings {
} }
if !path.exists() { if !path.exists() {
std::fs::create_dir_all(&path).unwrap(); std::fs::create_dir_all(path).unwrap();
} }
} }