1
0
Fork 0
mirror of https://github.com/zhaofengli/attic.git synced 2024-12-14 11:57:30 +00:00

Run rustfmt

This commit is contained in:
Zhaofeng Li 2023-01-04 21:05:07 -07:00
parent c04aff7c48
commit 69366cbe97
8 changed files with 31 additions and 25 deletions

View file

@ -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(())

View file

@ -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())
}
}

View file

@ -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?;

View file

@ -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,
}
}
}
}

View file

@ -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();

View file

@ -254,7 +254,8 @@ impl FromStr for Compression {
"zstd" => Ok(Self::Zstd),
_ => Err(ErrorKind::InvalidCompressionType {
name: s.to_string(),
}.into()),
}
.into()),
}
}
}

View file

@ -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))

View file

@ -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<Self> {
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<S: AsyncRead + Unpin + Send>(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;