mirror of
https://github.com/zhaofengli/attic.git
synced 2025-03-15 21:08:23 +00:00
Run rustfmt
This commit is contained in:
parent
c04aff7c48
commit
69366cbe97
8 changed files with 31 additions and 25 deletions
|
@ -82,7 +82,8 @@ impl NixNetrc {
|
||||||
.create(true)
|
.create(true)
|
||||||
.write(true)
|
.write(true)
|
||||||
.mode(FILE_MODE)
|
.mode(FILE_MODE)
|
||||||
.open(path).await?;
|
.open(path)
|
||||||
|
.await?;
|
||||||
|
|
||||||
file.write_all(content.as_bytes()).await?;
|
file.write_all(content.as_bytes()).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -114,9 +114,10 @@ pub(crate) async fn configure_cache(
|
||||||
update.retention_period = Set(None);
|
update.retention_period = Set(None);
|
||||||
}
|
}
|
||||||
RetentionPeriodConfig::Period(period) => {
|
RetentionPeriodConfig::Period(period) => {
|
||||||
update.retention_period = Set(Some(period.try_into().map_err(|_| {
|
update.retention_period =
|
||||||
ErrorKind::RequestError(anyhow!("Invalid 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(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(ErrorKind::RequestError(anyhow!(
|
Err(ErrorKind::RequestError(anyhow!("No modifiable fields were set.")).into())
|
||||||
"No modifiable fields were set."
|
|
||||||
)).into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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()))),
|
stream.map(|r| r.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))),
|
||||||
);
|
);
|
||||||
|
|
||||||
let username = req_state.auth.username()
|
let username = req_state.auth.username().map(str::to_string);
|
||||||
.map(str::to_string);
|
|
||||||
|
|
||||||
// Try to acquire a lock on an existing NAR
|
// Try to acquire a lock on an existing NAR
|
||||||
let existing_nar = database.find_and_lock_nar(&upload_info.nar_hash).await?;
|
let existing_nar = database.find_and_lock_nar(&upload_info.nar_hash).await?;
|
||||||
|
|
|
@ -133,7 +133,13 @@ impl StdError for ServerError {}
|
||||||
impl IntoResponse for ServerError {
|
impl IntoResponse for ServerError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
// TODO: Better logging control
|
// 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);
|
tracing::error!("{}", self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,4 +224,4 @@ impl ErrorKind {
|
||||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,8 +119,7 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
fn init_logging(tokio_console: bool) {
|
fn init_logging(tokio_console: bool) {
|
||||||
let env_filter = EnvFilter::from_default_env();
|
let env_filter = EnvFilter::from_default_env();
|
||||||
let fmt_layer = tracing_subscriber::fmt::layer()
|
let fmt_layer = tracing_subscriber::fmt::layer().with_filter(env_filter);
|
||||||
.with_filter(env_filter);
|
|
||||||
|
|
||||||
let error_layer = ErrorLayer::default();
|
let error_layer = ErrorLayer::default();
|
||||||
|
|
||||||
|
|
|
@ -254,7 +254,8 @@ impl FromStr for Compression {
|
||||||
"zstd" => Ok(Self::Zstd),
|
"zstd" => Ok(Self::Zstd),
|
||||||
_ => Err(ErrorKind::InvalidCompressionType {
|
_ => Err(ErrorKind::InvalidCompressionType {
|
||||||
name: s.to_string(),
|
name: s.to_string(),
|
||||||
}.into()),
|
}
|
||||||
|
.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,8 @@ impl StorageBackend for LocalBackend {
|
||||||
} else {
|
} else {
|
||||||
return Err(ErrorKind::StorageError(anyhow::anyhow!(
|
return Err(ErrorKind::StorageError(anyhow::anyhow!(
|
||||||
"Does not understand the remote file reference"
|
"Does not understand the remote file reference"
|
||||||
)).into());
|
))
|
||||||
|
.into());
|
||||||
};
|
};
|
||||||
|
|
||||||
fs::remove_file(self.get_path(&file.name))
|
fs::remove_file(self.get_path(&file.name))
|
||||||
|
@ -100,7 +101,8 @@ impl StorageBackend for LocalBackend {
|
||||||
} else {
|
} else {
|
||||||
return Err(ErrorKind::StorageError(anyhow::anyhow!(
|
return Err(ErrorKind::StorageError(anyhow::anyhow!(
|
||||||
"Does not understand the remote file reference"
|
"Does not understand the remote file reference"
|
||||||
)).into());
|
))
|
||||||
|
.into());
|
||||||
};
|
};
|
||||||
|
|
||||||
let file = File::open(self.get_path(&file.name))
|
let file = File::open(self.get_path(&file.name))
|
||||||
|
|
|
@ -5,8 +5,7 @@ use std::time::Duration;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use aws_sdk_s3::{
|
use aws_sdk_s3::{
|
||||||
config::Builder as S3ConfigBuilder, model::CompletedMultipartUpload, model::CompletedPart,
|
config::Builder as S3ConfigBuilder, model::CompletedMultipartUpload, model::CompletedPart,
|
||||||
presigning::config::PresigningConfig, Client, Credentials, Endpoint,
|
presigning::config::PresigningConfig, Client, Credentials, Endpoint, Region,
|
||||||
Region,
|
|
||||||
};
|
};
|
||||||
use futures::future::join_all;
|
use futures::future::join_all;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -74,7 +73,8 @@ pub struct S3RemoteFile {
|
||||||
|
|
||||||
impl S3Backend {
|
impl S3Backend {
|
||||||
pub async fn new(config: S3StorageConfig) -> ServerResult<Self> {
|
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()))
|
.region(Region::new(config.region.to_owned()))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -115,7 +115,8 @@ impl S3Backend {
|
||||||
} else {
|
} else {
|
||||||
return Err(ErrorKind::StorageError(anyhow::anyhow!(
|
return Err(ErrorKind::StorageError(anyhow::anyhow!(
|
||||||
"Does not understand the remote file reference"
|
"Does not understand the remote file reference"
|
||||||
)).into());
|
))
|
||||||
|
.into());
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: Ugly
|
// FIXME: Ugly
|
||||||
|
@ -123,7 +124,8 @@ impl S3Backend {
|
||||||
self.client.clone()
|
self.client.clone()
|
||||||
} else {
|
} else {
|
||||||
// FIXME: Cache the client instance
|
// 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()))
|
.region(Region::new(file.region.to_owned()))
|
||||||
.build();
|
.build();
|
||||||
Client::from_conf(s3_conf)
|
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 {
|
while cursor < CHUNK_SIZE {
|
||||||
let buf = &mut chunk[cursor..];
|
let buf = &mut chunk[cursor..];
|
||||||
let read = stream
|
let read = stream.read(buf).await.map_err(ServerError::storage_error)?;
|
||||||
.read(buf)
|
|
||||||
.await
|
|
||||||
.map_err(ServerError::storage_error)?;
|
|
||||||
|
|
||||||
if read == 0 {
|
if read == 0 {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue