From 1203a34f8fb93efa5c5c45956ec1e21e5c1eb1e7 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 1 Jan 2025 21:49:56 +0100 Subject: [PATCH] fix: some small bugs --- Dockerfile | 6 +++++- src/error.rs | 2 ++ src/server/mod.rs | 11 +++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5e8d868..9b64364 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,9 +13,13 @@ RUN wget -O - "https://github.com/Yelp/dumb-init/archive/refs/tags/v${DI_VER}.ta mv dumb-init .. && \ cd .. +COPY Cargo.toml Cargo.lock ./ + +RUN cargo fetch --locked + COPY . ./ -RUN cargo build --release +RUN cargo build --release --frozen FROM alpine:3.21 diff --git a/src/error.rs b/src/error.rs index fa58962..9d3c782 100644 --- a/src/error.rs +++ b/src/error.rs @@ -25,6 +25,8 @@ impl Error for ServerError {} impl IntoResponse for ServerError { fn into_response(self) -> Response { + tracing::error!("{}", self); + match self { ServerError::IO(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), ServerError::Axum(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), diff --git a/src/server/mod.rs b/src/server/mod.rs index 097ee25..4009d5e 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -32,9 +32,7 @@ pub fn app( // file doesn't exist, then we look for it in the other directories. let serve_dir = ServeDir::new(ctx.static_dir.join(STATIC_ROOT_NAME)) .append_index_html_on_directories(true) - .not_found_service( - ServeDir::new(ctx.static_dir.clone()).append_index_html_on_directories(true), - ); + .fallback(ServeDir::new(ctx.static_dir.clone()).append_index_html_on_directories(true)); let mut app = Router::new() .route_service("/", serve_dir.clone()) @@ -101,8 +99,13 @@ fn process_archive(ar_path: &Path, dest_dir: &Path) -> io::Result<()> { .unwrap_or(String::from("")); let new_dir = dest_dir.with_extension(format!("{ext}.new")); + // Directory might be left behind by previous failed upload + if new_dir.try_exists()? { + std::fs::remove_dir_all(&new_dir)?; + } + // Unpack archive into new directory - std::fs::create_dir(&new_dir)?; + std::fs::create_dir_all(&new_dir)?; ar.unpack(&new_dir)?; // Replace original directory with new one