From 51cccce029365a610abd77445a43dae6d496dbd6 Mon Sep 17 00:00:00 2001 From: zsofiak96 Date: Sun, 26 Nov 2023 16:22:48 +0100 Subject: [PATCH 1/2] refactor(build-result-archive): Change result packaging to tar --- src/command/execute_program.rs | 24 ++++++++++++++++-------- src/command/return_result.rs | 6 +++--- src/command/store_archive.rs | 1 + 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/command/execute_program.rs b/src/command/execute_program.rs index 46dcdcb..ce83ff4 100644 --- a/src/command/execute_program.rs +++ b/src/command/execute_program.rs @@ -42,7 +42,7 @@ pub fn execute_program( log::info!("Program {}:{} finished with {}", program_id, timestamp, exit_code); let sid = ProgramStatus { program_id, timestamp, exit_code }; let rid = ResultId { program_id, timestamp }; - build_result_archive(rid).unwrap(); // create the zip file with result and log + build_result_archive(rid).unwrap(); // create the tar file with result and log let mut context = wd_context.lock().unwrap(); context.event_vec.push(Event::Status(sid)).unwrap(); @@ -135,13 +135,13 @@ fn run_until_timeout( Err(()) } -/// The function uses `zip` to create an uncompressed archive that includes the result file specified, as well as +/// The function uses `tar` to create an uncompressed archive that includes the result file specified, as well as /// the programs stdout/stderr and the schedulers log file. If any of the files is missing, the archive /// is created without them. fn build_result_archive(res: ResultId) -> Result<(), std::io::Error> { let res_path = format!("./archives/{}/results/{}", res.program_id, res.timestamp); let log_path = format!("./data/{}_{}.log", res.program_id, res.timestamp); - let out_path = format!("./data/{}_{}.zip", res.program_id, res.timestamp); + let out_path = format!("./data/{}_{}.tar", res.program_id, res.timestamp); const MAXIMUM_FILE_SIZE: u64 = 1_000_000; for path in [&res_path, &log_path, &out_path, &"log".into()] { @@ -150,13 +150,21 @@ fn build_result_archive(res: ResultId) -> Result<(), std::io::Error> { } } - let _ = Command::new("zip") - .arg("-0") + let path_to_res = format!("./archives/{}/results", res.program_id); + let result = format!("{}", res.timestamp); + let path_to_log = String::from("../../../data"); + let log = format!("{}_{}.log", res.program_id, res.timestamp); + let _ = Command::new("tar") + .arg("-cf") .arg(out_path) - .arg("--junk-paths") + .arg("--exclude") .arg("log") - .arg(res_path) - .arg(log_path) + .arg("-C") + .arg(path_to_res) + .arg(result) + .arg("-C") + .arg(path_to_log) + .arg(log) .status(); Ok(()) diff --git a/src/command/return_result.rs b/src/command/return_result.rs index 31b3c57..03548a5 100644 --- a/src/command/return_result.rs +++ b/src/command/return_result.rs @@ -5,7 +5,7 @@ use crate::{ use super::{truncate_to_size, CommandResult, SyncExecutionContext}; -/// Handles a complete return result command. The result zip file is only deleted if a final ACK is +/// Handles a complete return result command. The result tar file is only deleted if a final ACK is /// received. pub fn return_result( data: Vec, @@ -17,7 +17,7 @@ pub fn return_result( let program_id = u16::from_le_bytes([data[1], data[2]]); let timestamp = u32::from_le_bytes([data[3], data[4], data[5], data[6]]); - let result_path = format!("./data/{}_{}.zip", program_id, timestamp); + let result_path = format!("./data/{}_{}.tar", program_id, timestamp); if !std::path::Path::new(&result_path).exists() { return Err(CommandError::ProtocolViolation( @@ -52,7 +52,7 @@ pub fn return_result( fn delete_result(res: ResultId) -> CommandResult { let res_path = format!("./archives/{}/results/{}", res.program_id, res.timestamp); let log_path = format!("./data/{}_{}.log", res.program_id, res.timestamp); - let out_path = format!("./data/{}_{}.zip", res.program_id, res.timestamp); + let out_path = format!("./data/{}_{}.tar", res.program_id, res.timestamp); let _ = std::fs::remove_file(res_path); let _ = std::fs::remove_file(log_path); let _ = std::fs::remove_file(out_path); diff --git a/src/command/store_archive.rs b/src/command/store_archive.rs index 3e93d61..dd4281f 100644 --- a/src/command/store_archive.rs +++ b/src/command/store_archive.rs @@ -32,6 +32,7 @@ pub fn store_archive( /// /// Returns Ok or passes along a file access/unzip process error fn unpack_archive(folder: String, bytes: Vec) -> CommandResult { + // Store bytes into temporary file // Store bytes into temporary file let zip_path = format!("./data/{}.zip", folder); let mut zip_file = std::fs::File::create(&zip_path)?; From ad37483e150ae8794ff0019a19ac03aa0e221fc4 Mon Sep 17 00:00:00 2001 From: zsofiak96 Date: Sun, 3 Dec 2023 16:41:03 +0100 Subject: [PATCH 2/2] test: Adjust tests to result packaging to tar --- tests/software_tests/return_result.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/software_tests/return_result.rs b/tests/software_tests/return_result.rs index b108e36..84daad1 100644 --- a/tests/software_tests/return_result.rs +++ b/tests/software_tests/return_result.rs @@ -77,7 +77,7 @@ fn truncate_result() -> TestResult { command::handle_command(&mut com, &mut exec); assert!(com.is_complete()); - assert!(std::fs::File::open("./data/8_5.zip")?.metadata()?.len() < 1_001_000); + assert!(std::fs::File::open("./data/8_5.tar")?.metadata()?.len() < 1_001_000); common::cleanup("8"); Ok(()) @@ -119,7 +119,7 @@ fn stopped_return() -> TestResult { command::handle_command(&mut com, &mut exec); assert!(com.is_complete()); - assert!(std::fs::File::open("./data/9_5.zip").is_ok()); + assert!(std::fs::File::open("./data/9_5.tar").is_ok()); common::cleanup("9"); Ok(()) @@ -159,7 +159,7 @@ fn result_is_not_deleted_after_corrupted_transfer() -> TestResult { command::handle_command(&mut com, &mut exec); assert!(com.is_complete()); - assert!(std::fs::File::open("./data/50_0.zip").is_ok()); + assert!(std::fs::File::open("./data/50_0.tar").is_ok()); common::cleanup("50"); Ok(())