Prevent empty archive extraction

This commit is contained in:
Pierre HUBERT 2022-03-27 14:29:11 +02:00
parent c100d87145
commit d85cce8264

View File

@ -5,7 +5,7 @@ use actix_files::{Files, NamedFile};
use actix_multipart::Multipart;
use actix_web::{App, Error, HttpRequest, HttpResponse, HttpServer, web};
use actix_web::dev::{fn_service, ServiceRequest, ServiceResponse};
use actix_web::error::{ErrorInternalServerError, ErrorUnauthorized};
use actix_web::error::{ErrorBadRequest, ErrorInternalServerError, ErrorUnauthorized};
use actix_web::middleware::Logger;
use bytes::BufMut;
use clap::Parser;
@ -178,6 +178,11 @@ async fn replace_files(args: web::Data<Args>, req: HttpRequest, mut payload: Mul
}
}
// Check if at least a file was sent
if new_files.is_empty() {
return Err(ErrorBadRequest("No file to extract!"));
}
// Delete all current files in storage
for entry in std::fs::read_dir(args.storage_path())? {
let entry = entry?;