From 69366cbe9793191196331c36f2d1adf0ad8d043a Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Wed, 4 Jan 2023 21:05:07 -0700 Subject: [PATCH] Run rustfmt --- client/src/nix_netrc.rs | 3 ++- server/src/api/v1/cache_config.rs | 11 +++++------ server/src/api/v1/upload_path.rs | 3 +-- server/src/error.rs | 10 ++++++++-- server/src/main.rs | 3 +-- server/src/narinfo/mod.rs | 3 ++- server/src/storage/local.rs | 6 ++++-- server/src/storage/s3.rs | 17 ++++++++--------- 8 files changed, 31 insertions(+), 25 deletions(-) diff --git a/client/src/nix_netrc.rs b/client/src/nix_netrc.rs index 721ba07..b82e7b2 100644 --- a/client/src/nix_netrc.rs +++ b/client/src/nix_netrc.rs @@ -82,7 +82,8 @@ impl NixNetrc { .create(true) .write(true) .mode(FILE_MODE) - .open(path).await?; + .open(path) + .await?; file.write_all(content.as_bytes()).await?; Ok(()) diff --git a/server/src/api/v1/cache_config.rs b/server/src/api/v1/cache_config.rs index de8b3e0..4626ecf 100644 --- a/server/src/api/v1/cache_config.rs +++ b/server/src/api/v1/cache_config.rs @@ -114,9 +114,10 @@ pub(crate) async fn configure_cache( update.retention_period = Set(None); } RetentionPeriodConfig::Period(period) => { - update.retention_period = Set(Some(period.try_into().map_err(|_| { - ErrorKind::RequestError(anyhow!("Invalid retention period")) - })?)); + update.retention_period = + Set(Some(period.try_into().map_err(|_| { + ErrorKind::RequestError(anyhow!("Invalid retention period")) + })?)); } } @@ -131,9 +132,7 @@ pub(crate) async fn configure_cache( Ok(()) } else { - Err(ErrorKind::RequestError(anyhow!( - "No modifiable fields were set." - )).into()) + Err(ErrorKind::RequestError(anyhow!("No modifiable fields were set.")).into()) } } diff --git a/server/src/api/v1/upload_path.rs b/server/src/api/v1/upload_path.rs index c0e88a9..7c6e2bd 100644 --- a/server/src/api/v1/upload_path.rs +++ b/server/src/api/v1/upload_path.rs @@ -107,8 +107,7 @@ pub(crate) async fn upload_path( stream.map(|r| r.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))), ); - let username = req_state.auth.username() - .map(str::to_string); + let username = req_state.auth.username().map(str::to_string); // Try to acquire a lock on an existing NAR let existing_nar = database.find_and_lock_nar(&upload_info.nar_hash).await?; diff --git a/server/src/error.rs b/server/src/error.rs index bc4b50d..dcd559d 100644 --- a/server/src/error.rs +++ b/server/src/error.rs @@ -133,7 +133,13 @@ impl StdError for ServerError {} impl IntoResponse for ServerError { fn into_response(self) -> Response { // TODO: Better logging control - if matches!(self.kind, ErrorKind::DatabaseError(_) | ErrorKind::StorageError(_) | ErrorKind::ManifestSerializationError(_) | ErrorKind::AtticError(_)) { + if matches!( + self.kind, + ErrorKind::DatabaseError(_) + | ErrorKind::StorageError(_) + | ErrorKind::ManifestSerializationError(_) + | ErrorKind::AtticError(_) + ) { tracing::error!("{}", self); } @@ -218,4 +224,4 @@ impl ErrorKind { _ => StatusCode::INTERNAL_SERVER_ERROR, } } -} \ No newline at end of file +} diff --git a/server/src/main.rs b/server/src/main.rs index 2b18f79..762528f 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -119,8 +119,7 @@ async fn main() -> Result<()> { fn init_logging(tokio_console: bool) { let env_filter = EnvFilter::from_default_env(); - let fmt_layer = tracing_subscriber::fmt::layer() - .with_filter(env_filter); + let fmt_layer = tracing_subscriber::fmt::layer().with_filter(env_filter); let error_layer = ErrorLayer::default(); diff --git a/server/src/narinfo/mod.rs b/server/src/narinfo/mod.rs index 2bca816..dd26210 100644 --- a/server/src/narinfo/mod.rs +++ b/server/src/narinfo/mod.rs @@ -254,7 +254,8 @@ impl FromStr for Compression { "zstd" => Ok(Self::Zstd), _ => Err(ErrorKind::InvalidCompressionType { name: s.to_string(), - }.into()), + } + .into()), } } } diff --git a/server/src/storage/local.rs b/server/src/storage/local.rs index a8fe6c5..383ed4f 100644 --- a/server/src/storage/local.rs +++ b/server/src/storage/local.rs @@ -76,7 +76,8 @@ impl StorageBackend for LocalBackend { } else { return Err(ErrorKind::StorageError(anyhow::anyhow!( "Does not understand the remote file reference" - )).into()); + )) + .into()); }; fs::remove_file(self.get_path(&file.name)) @@ -100,7 +101,8 @@ impl StorageBackend for LocalBackend { } else { return Err(ErrorKind::StorageError(anyhow::anyhow!( "Does not understand the remote file reference" - )).into()); + )) + .into()); }; let file = File::open(self.get_path(&file.name)) diff --git a/server/src/storage/s3.rs b/server/src/storage/s3.rs index e284e08..a0963b3 100644 --- a/server/src/storage/s3.rs +++ b/server/src/storage/s3.rs @@ -5,8 +5,7 @@ use std::time::Duration; use async_trait::async_trait; use aws_sdk_s3::{ config::Builder as S3ConfigBuilder, model::CompletedMultipartUpload, model::CompletedPart, - presigning::config::PresigningConfig, Client, Credentials, Endpoint, - Region, + presigning::config::PresigningConfig, Client, Credentials, Endpoint, Region, }; use futures::future::join_all; use serde::{Deserialize, Serialize}; @@ -74,7 +73,8 @@ pub struct S3RemoteFile { impl S3Backend { pub async fn new(config: S3StorageConfig) -> ServerResult { - let s3_config = Self::config_builder(&config).await? + let s3_config = Self::config_builder(&config) + .await? .region(Region::new(config.region.to_owned())) .build(); @@ -115,7 +115,8 @@ impl S3Backend { } else { return Err(ErrorKind::StorageError(anyhow::anyhow!( "Does not understand the remote file reference" - )).into()); + )) + .into()); }; // FIXME: Ugly @@ -123,7 +124,8 @@ impl S3Backend { self.client.clone() } else { // FIXME: Cache the client instance - let s3_conf = Self::config_builder(&self.config).await? + let s3_conf = Self::config_builder(&self.config) + .await? .region(Region::new(file.region.to_owned())) .build(); Client::from_conf(s3_conf) @@ -356,10 +358,7 @@ async fn read_chunk_async(stream: &mut S) -> Server while cursor < CHUNK_SIZE { let buf = &mut chunk[cursor..]; - let read = stream - .read(buf) - .await - .map_err(ServerError::storage_error)?; + let read = stream.read(buf).await.map_err(ServerError::storage_error)?; if read == 0 { break;