Can restore disk image when adding disks to virtual machine
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2025-05-30 14:41:48 +02:00
parent ec9492c933
commit 1d4af8c74e
8 changed files with 132 additions and 40 deletions

View File

@ -49,7 +49,7 @@ pub async fn upload(MultipartForm(mut form): MultipartForm<UploadDiskImageForm>)
}
// Check if a file with the same name already exists
let dest_path = AppConfig::get().disk_images_storage_path().join(file_name);
let dest_path = AppConfig::get().disk_images_file_path(&file_name);
if dest_path.is_file() {
return Ok(HttpResponse::Conflict().json("A file with the same name already exists!"));
}
@ -82,9 +82,7 @@ pub async fn download(p: web::Path<DiskFilePath>, req: HttpRequest) -> HttpResul
return Ok(HttpResponse::BadRequest().json("Invalid file name!"));
}
let file_path = AppConfig::get()
.disk_images_storage_path()
.join(&p.filename);
let file_path = AppConfig::get().disk_images_file_path(&p.filename);
if !file_path.exists() {
return Ok(HttpResponse::NotFound().json("Disk image does not exists!"));
@ -109,9 +107,7 @@ pub async fn convert(
return Ok(HttpResponse::BadRequest().json("Invalid src file name!"));
}
let src_file_path = AppConfig::get()
.disk_images_storage_path()
.join(&p.filename);
let src_file_path = AppConfig::get().disk_images_file_path(&p.filename);
let src = DiskFileInfo::load_file(&src_file_path)?;
@ -176,9 +172,7 @@ pub async fn handle_convert_request(
return Ok(HttpResponse::BadRequest().json("Invalid destination file extension!"));
}
let dst_file_path = AppConfig::get()
.disk_images_storage_path()
.join(&req.dest_file_name);
let dst_file_path = AppConfig::get().disk_images_file_path(&req.dest_file_name);
if dst_file_path.exists() {
return Ok(HttpResponse::Conflict().json("Specified destination file already exists!"));
@ -201,9 +195,7 @@ pub async fn delete(p: web::Path<DiskFilePath>) -> HttpResult {
return Ok(HttpResponse::BadRequest().json("Invalid file name!"));
}
let file_path = AppConfig::get()
.disk_images_storage_path()
.join(&p.filename);
let file_path = AppConfig::get().disk_images_file_path(&p.filename);
if !file_path.exists() {
return Ok(HttpResponse::NotFound().json("Disk image does not exists!"));