chore: rustfmt the workspace and make clippy -D warnings pass

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 19:19:21 +07:00
parent d7fe99edd7
commit f13f0e6953
46 changed files with 6606 additions and 1496 deletions

View File

@@ -1,12 +1,9 @@
use super::routes::{admin_write, authenticate};
use crate::auth::{AuditAction, AuditOutcome, AuditResource, Permission};
use crate::exports::{self, Guarded, Refused, EXPORT_PREFIX};
use crate::state::HubState;
use async_compression::tokio::bufread::GzipEncoder;
use axum::body::Bytes;
use futures_core::Stream;
use std::pin::Pin;
use tokio::io::{AsyncReadExt, AsyncSeekExt};
use crate::state::HubState;
use axum::{
body::Body,
extract::{ConnectInfo, Path, State},
@@ -15,7 +12,10 @@ use axum::{
routing::get,
Router,
};
use futures_core::Stream;
use std::net::SocketAddr;
use std::pin::Pin;
use tokio::io::{AsyncReadExt, AsyncSeekExt};
use tokio_util::io::ReaderStream;
use uuid::Uuid;
@@ -51,10 +51,24 @@ async fn download(
.map_err(internal)?
.filter(|snapshot| snapshot.manifest.provider != "legacy-history")
.ok_or(StatusCode::NOT_FOUND)?;
super::gate::scoped(&state, &actor, Permission::SnapshotDownload, snapshot.manifest.orbit_id)?;
super::gate::scoped(
&state,
&actor,
Permission::SnapshotDownload,
snapshot.manifest.orbit_id,
)?;
let audit = |action: AuditAction, outcome: AuditOutcome| {
state.db.audit_event(&actor.principal, action, AuditResource::Snapshot(id), outcome, actor.request_id).map_err(internal)
state
.db
.audit_event(
&actor.principal,
action,
AuditResource::Snapshot(id),
outcome,
actor.request_id,
)
.map_err(internal)
};
audit(AuditAction::ExportRequested, AuditOutcome::Allowed)?;
let permit = match state.exports.admit(&state.data_dir, snapshot.size_bytes) {
@@ -67,15 +81,23 @@ async fn download(
});
}
};
let staging = tempfile::Builder::new().prefix(EXPORT_PREFIX).tempdir_in(&state.data_dir).map_err(internal)?;
let staging = tempfile::Builder::new()
.prefix(EXPORT_PREFIX)
.tempdir_in(&state.data_dir)
.map_err(internal)?;
let path = staging.path().join("download");
state.export_snapshot(id, path.clone()).await.map_err(internal)?;
state
.export_snapshot(id, path.clone())
.await
.map_err(internal)?;
let mut file = tokio::fs::File::open(&path).await.map_err(internal)?;
let size = file.metadata().await.map_err(internal)?.len();
let mut head = vec![0u8; 512];
let read = file.read(&mut head).await.map_err(internal)?;
head.truncate(read);
file.seek(std::io::SeekFrom::Start(0)).await.map_err(internal)?;
file.seek(std::io::SeekFrom::Start(0))
.await
.map_err(internal)?;
let plan = exports::plan(&snapshot.manifest.restore_hints, &head);
audit(AuditAction::ExportReady, AuditOutcome::Succeeded)?;
@@ -85,16 +107,31 @@ async fn download(
} else {
Box::pin(ReaderStream::with_capacity(reader, CHUNK))
};
let body = Guarded::new(stream, permit, staging, state.db.clone(), actor.principal.clone(), id, actor.request_id);
let body = Guarded::new(
stream,
permit,
staging,
state.db.clone(),
actor.principal.clone(),
id,
actor.request_id,
);
let mut response = Response::new(Body::from_stream(body));
let headers = response.headers_mut();
headers.insert(header::CONTENT_TYPE, HeaderValue::from_static(plan.content_type));
headers.insert(
header::CONTENT_TYPE,
HeaderValue::from_static(plan.content_type),
);
headers.insert(
header::CONTENT_DISPOSITION,
HeaderValue::from_str(&format!("attachment; filename=\"{id}.{}\"", plan.extension)).map_err(internal)?,
HeaderValue::from_str(&format!("attachment; filename=\"{id}.{}\"", plan.extension))
.map_err(internal)?,
);
headers.insert(header::CACHE_CONTROL, HeaderValue::from_static("no-store"));
headers.insert(header::X_CONTENT_TYPE_OPTIONS, HeaderValue::from_static("nosniff"));
headers.insert(
header::X_CONTENT_TYPE_OPTIONS,
HeaderValue::from_static("nosniff"),
);
// The exact size is only known when the bytes are sent as they are. Never `Content-Encoding`: this
// is the file itself, and a browser must not unpack it.
if !plan.compress {
@@ -112,11 +149,16 @@ async fn delete(
let actor = admin_write(&state, peer, &headers)?;
let mut vault = state.vault.clone().write_owned().await;
if state.db.snapshot_in_restore(id).map_err(internal)?
|| state.db.offsite_pending(id).map_err(internal)? || state.active_exports().await.contains(&id)
|| state.db.offsite_pending(id).map_err(internal)?
|| state.active_exports().await.contains(&id)
{
return Err(StatusCode::CONFLICT);
}
if vault.get_snapshot(id).map_err(internal)?.is_none_or(|snapshot| snapshot.manifest.provider == "legacy-history") {
if vault
.get_snapshot(id)
.map_err(internal)?
.is_none_or(|snapshot| snapshot.manifest.provider == "legacy-history")
{
return Err(StatusCode::NOT_FOUND);
}
state