From 48f2d00c943e5b9f789131c0bb91091f5c534497 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Mon, 27 May 2024 22:56:37 +0200 Subject: [PATCH] chore: clean up imports --- server/Cargo.toml | 3 ++- server/src/api/mod.rs | 12 ++++++------ server/src/cli.rs | 16 +++++++--------- server/src/db/mod.rs | 7 +++---- server/src/db/query/package.rs | 4 ++-- server/src/db/query/repo.rs | 4 ++-- server/src/error.rs | 10 +++++----- server/src/main.rs | 6 +++--- server/src/repo/archive.rs | 14 +++++++++----- server/src/repo/manager_new.rs | 13 +++++-------- server/src/repo/mod.rs | 20 ++++++++++---------- server/src/repo/package.rs | 20 ++++++++++++-------- 12 files changed, 66 insertions(+), 63 deletions(-) diff --git a/server/Cargo.toml b/server/Cargo.toml index 1d5dc1d..03ff93e 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -32,5 +32,6 @@ features = [ "sqlx-postgres", "runtime-tokio-rustls", "macros", - "with-chrono" + "with-chrono", + "debug-print" ] diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs index fd54cd8..0a0a56e 100644 --- a/server/src/api/mod.rs +++ b/server/src/api/mod.rs @@ -1,13 +1,13 @@ mod pagination; -use axum::extract::{Path, Query, State}; -use axum::routing::get; -use axum::Json; -use axum::Router; - +use crate::db; use pagination::PaginatedResponse; -use crate::db; +use axum::{ + extract::{Path, Query, State}, + routing::get, + Json, Router, +}; pub fn router() -> Router { Router::new() diff --git a/server/src/cli.rs b/server/src/cli.rs index 2d61ad4..db7f705 100644 --- a/server/src/cli.rs +++ b/server/src/cli.rs @@ -1,13 +1,9 @@ -use crate::repo::MetaRepoMgr; -use crate::{Config, Global}; +use crate::{repo::MetaRepoMgr, Config, Global}; -use axum::extract::FromRef; -use axum::Router; +use axum::{extract::FromRef, Router}; use clap::Parser; use sea_orm_migration::MigratorTrait; -use std::io; -use std::path::PathBuf; -use std::sync::Arc; +use std::{io, path::PathBuf, sync::Arc}; use tokio::sync::RwLock; use tower_http::trace::TraceLayer; use tracing::debug; @@ -40,7 +36,7 @@ pub struct Cli { #[arg( long, value_name = "LOG_LEVEL", - default_value = "tower_http=debug,rieterd=debug", + default_value = "tower_http=debug,rieterd=debug,sea_orm=debug", env = "RIETER_LOG" )] pub log: String, @@ -67,7 +63,7 @@ impl Cli { url.clone() } else { format!( - "sqlite://{}", + "sqlite://{}?mode=rwc", self.data_dir.join("rieter.sqlite").to_string_lossy() ) }; @@ -80,6 +76,8 @@ impl Cli { let db = sea_orm::Database::connect(options).await?; crate::db::Migrator::up(&db, None).await?; + debug!("Successfully applied migrations"); + let config = Config { data_dir: self.data_dir.clone(), }; diff --git a/server/src/db/mod.rs b/server/src/db/mod.rs index 0194079..597cf20 100644 --- a/server/src/db/mod.rs +++ b/server/src/db/mod.rs @@ -2,13 +2,12 @@ pub mod entities; mod migrator; pub mod query; -use sea_orm::{DeriveActiveEnum, EnumIter}; - -use serde::{Deserialize, Serialize}; - pub use entities::{prelude::*, *}; pub use migrator::Migrator; +use sea_orm::{DeriveActiveEnum, EnumIter}; +use serde::{Deserialize, Serialize}; + type Result = std::result::Result; #[derive(EnumIter, DeriveActiveEnum, Serialize, Deserialize, PartialEq, Eq, Clone, Debug)] diff --git a/server/src/db/query/package.rs b/server/src/db/query/package.rs index 31f3464..8a211bf 100644 --- a/server/src/db/query/package.rs +++ b/server/src/db/query/package.rs @@ -1,8 +1,8 @@ +use crate::db::*; + use sea_orm::{sea_query::IntoCondition, *}; use serde::Deserialize; -use crate::db::*; - #[derive(Deserialize)] pub struct Filter { repo: Option, diff --git a/server/src/db/query/repo.rs b/server/src/db/query/repo.rs index dfc92ad..94627f7 100644 --- a/server/src/db/query/repo.rs +++ b/server/src/db/query/repo.rs @@ -1,7 +1,7 @@ -use sea_orm::{sea_query::IntoCondition, *}; - use crate::db::*; +use sea_orm::{sea_query::IntoCondition, *}; + #[derive(Deserialize)] pub struct Filter { name: Option, diff --git a/server/src/error.rs b/server/src/error.rs index d0ba36b..5c3e920 100644 --- a/server/src/error.rs +++ b/server/src/error.rs @@ -1,9 +1,9 @@ -use std::error::Error; -use std::fmt; -use std::io; +use std::{error::Error, fmt, io}; -use axum::http::StatusCode; -use axum::response::{IntoResponse, Response}; +use axum::{ + http::StatusCode, + response::{IntoResponse, Response}, +}; pub type Result = std::result::Result; diff --git a/server/src/main.rs b/server/src/main.rs index 32360e2..c539b9e 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -4,11 +4,11 @@ pub mod db; mod error; mod repo; -use clap::Parser; pub use error::{Result, ServerError}; use repo::MetaRepoMgr; -use std::path::PathBuf; -use std::sync::Arc; + +use clap::Parser; +use std::{path::PathBuf, sync::Arc}; use tokio::sync::RwLock; #[derive(Clone)] diff --git a/server/src/repo/archive.rs b/server/src/repo/archive.rs index bce0d1a..d103f13 100644 --- a/server/src/repo/archive.rs +++ b/server/src/repo/archive.rs @@ -1,9 +1,13 @@ -use std::io; -use std::path::{Path, PathBuf}; -use std::sync::{Arc, Mutex}; +use std::{ + io, + path::{Path, PathBuf}, + sync::{Arc, Mutex}, +}; -use libarchive::write::{Builder, FileWriter, WriteEntry}; -use libarchive::{Entry, WriteFilter, WriteFormat}; +use libarchive::{ + write::{Builder, FileWriter, WriteEntry}, + Entry, WriteFilter, WriteFormat, +}; /// Struct to abstract away the intrinsics of writing entries to an archive file pub struct RepoArchiveWriter { diff --git a/server/src/repo/manager_new.rs b/server/src/repo/manager_new.rs index e7ffe65..4d60bcf 100644 --- a/server/src/repo/manager_new.rs +++ b/server/src/repo/manager_new.rs @@ -1,15 +1,12 @@ +use super::{archive, package}; +use crate::{db, error::Result}; + use std::path::{Path, PathBuf}; -use sea_orm::{ColumnTrait, DbConn, ModelTrait, QueryFilter, QuerySelect}; -use uuid::Uuid; - use futures::StreamExt; +use sea_orm::{ColumnTrait, DbConn, ModelTrait, QueryFilter, QuerySelect}; use tokio::io::AsyncRead; - -use super::archive; -use super::package; -use crate::db; -use crate::error::Result; +use uuid::Uuid; pub const ANY_ARCH: &'static str = "any"; diff --git a/server/src/repo/mod.rs b/server/src/repo/mod.rs index 87cfda1..072ceef 100644 --- a/server/src/repo/mod.rs +++ b/server/src/repo/mod.rs @@ -4,19 +4,19 @@ mod manager_new; pub mod package; pub use manager_new::MetaRepoMgr; -use tokio_util::io::StreamReader; -use axum::body::Body; -use axum::extract::{Path, State}; -use axum::http::Request; -use axum::http::StatusCode; -use axum::response::IntoResponse; -use axum::routing::{delete, post}; -use axum::Router; +use axum::{ + body::Body, + extract::{Path, State}, + http::{Request, StatusCode}, + response::IntoResponse, + routing::{delete, post}, + Router, +}; use futures::TryStreamExt; +use tokio_util::io::StreamReader; use tower::util::ServiceExt; -use tower_http::services::ServeFile; -use tower_http::validate_request::ValidateRequestHeaderLayer; +use tower_http::{services::ServeFile, validate_request::ValidateRequestHeaderLayer}; pub fn router(api_key: &str) -> Router { Router::new() diff --git a/server/src/repo/package.rs b/server/src/repo/package.rs index 980cbb6..24979eb 100644 --- a/server/src/repo/package.rs +++ b/server/src/repo/package.rs @@ -1,16 +1,20 @@ +use crate::db::{self, entities::package, PackageRelatedEnum}; + +use std::{ + fmt, fs, + io::{self, BufRead, BufReader, BufWriter, Read, Write}, + path::{Path, PathBuf}, +}; + use chrono::NaiveDateTime; use futures::StreamExt; -use libarchive::read::{Archive, Builder}; -use libarchive::{Entry, ReadFilter}; +use libarchive::{ + read::{Archive, Builder}, + Entry, ReadFilter, +}; use sea_orm::{ActiveValue::Set, ColumnTrait, DbConn, ModelTrait, QueryFilter, QuerySelect}; -use std::fmt; -use std::fs; -use std::io::{self, BufRead, BufReader, BufWriter, Read, Write}; -use std::path::{Path, PathBuf}; use tokio::io::{AsyncWrite, AsyncWriteExt}; -use crate::db::{self, entities::package, PackageRelatedEnum}; - const IGNORED_FILES: [&str; 5] = [".BUILDINFO", ".INSTALL", ".MTREE", ".PKGINFO", ".CHANGELOG"]; #[derive(Debug, Clone)]