Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(build-result-archive): Change result packaging to tar #128

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/command/execute_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()] {
Expand All @@ -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(())
Expand Down
6 changes: 3 additions & 3 deletions src/command/return_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
Expand All @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/command/store_archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) -> 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)?;
Expand Down
6 changes: 3 additions & 3 deletions tests/software_tests/return_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down
Loading