From 01ff365af58b61a64d0dcf7f056fb2b11465e5fa Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 26 Nov 2024 15:39:03 +0000 Subject: [PATCH] feat(jstzd): use symlink for rollup --- crates/jstzd/src/task/octez_rollup.rs | 44 +++------------------------ crates/jstzd/tests/utils.rs | 2 +- 2 files changed, 5 insertions(+), 41 deletions(-) diff --git a/crates/jstzd/src/task/octez_rollup.rs b/crates/jstzd/src/task/octez_rollup.rs index 104cc33c1..8251371c1 100644 --- a/crates/jstzd/src/task/octez_rollup.rs +++ b/crates/jstzd/src/task/octez_rollup.rs @@ -1,5 +1,5 @@ use std::{ - fs::{self, create_dir_all}, + os::unix::fs::symlink, path::{Path, PathBuf}, sync::Arc, }; @@ -7,7 +7,7 @@ use std::{ use crate::task::child_wrapper::ChildWrapper; use super::{child_wrapper::SharedChildWrapper, Task}; -use anyhow::{anyhow, Result}; +use anyhow::Result; use async_trait::async_trait; use octez::r#async::{ directory::Directory, @@ -46,9 +46,8 @@ impl Task for OctezRollup { preimages_dir: from, } => { let temp_dir = Directory::default(); - let to = PathBuf::from(&temp_dir).join(config.pvm_kind.to_string()); - create_dir_all(&to)?; - copy_files(from, &to)?; + let to = Path::new(&temp_dir).join(config.pvm_kind.to_string()); + symlink(from, to)?; temp_dir } RollupDataDir::Temp => Directory::default(), @@ -86,38 +85,3 @@ impl Task for OctezRollup { return Ok(body.healthy); } } - -/// Copy all files from `src_dir` to `dest_dir` -fn copy_files(src_dir: &Path, dest_dir: &Path) -> Result<()> { - for entry in fs::read_dir(src_dir)? { - let path = entry?.path(); - if path.is_file() { - let file_name = path - .file_name() - .ok_or_else(|| anyhow!("file name not found in path: {:?}", path))?; - let dest_file = dest_dir.join(file_name); - fs::copy(&path, &dest_file)?; - } - } - Ok(()) -} - -#[cfg(test)] -mod test { - use super::copy_files; - - #[test] - fn test_copy_files() { - let temp_dir = tempfile::tempdir().unwrap(); - let src_dir = temp_dir.path().join("src"); - let dest_dir = temp_dir.path().join("dest"); - std::fs::create_dir(&src_dir).unwrap(); - std::fs::create_dir(&dest_dir).unwrap(); - let src_file = src_dir.join("file.txt"); - std::fs::write(&src_file, "hello").unwrap(); - copy_files(&src_dir, &dest_dir).unwrap(); - let dest_file = dest_dir.join("file.txt"); - assert!(dest_file.exists()); - assert_eq!(std::fs::read_to_string(&dest_file).unwrap(), "hello"); - } -} diff --git a/crates/jstzd/tests/utils.rs b/crates/jstzd/tests/utils.rs index 2d9ccd888..db6e3c346 100644 --- a/crates/jstzd/tests/utils.rs +++ b/crates/jstzd/tests/utils.rs @@ -52,7 +52,7 @@ pub async fn spawn_rollup( let rollup = octez_rollup::OctezRollup::spawn(config) .await .expect("Failed to spawn rollup"); - let rollup_ready = retry(10, 1000, || async { rollup.health_check().await }).await; + let rollup_ready = retry(30, 1000, || async { rollup.health_check().await }).await; assert!(rollup_ready); rollup }