diff --git a/src/fs-gen/Cargo.toml b/src/fs-gen/Cargo.toml index 0a0b17d..9790eb3 100644 --- a/src/fs-gen/Cargo.toml +++ b/src/fs-gen/Cargo.toml @@ -9,4 +9,7 @@ edition = "2021" clap = { version = "4.5.3", features = ["derive", "wrap_help", "string"] } once_cell = "1.19.0" regex = "1.10.4" +serde = { version = "1.0.197", features = ["derive"] } +serde_json = "1.0.115" validator = { version = "0.17.0", features = ["derive"] } +vfs = "0.12.0" diff --git a/src/fs-gen/src/image_builder.rs b/src/fs-gen/src/image_builder.rs new file mode 100644 index 0000000..8319048 --- /dev/null +++ b/src/fs-gen/src/image_builder.rs @@ -0,0 +1,22 @@ +use std::path::{Path, PathBuf}; + +use vfs::{FileSystem, OverlayFS, PhysicalFS, VfsPath}; + +pub fn build_new_image(blob_paths: &Vec, output_folder: &Path) { + let virtual_paths = blob_paths + .iter() + .map(|p| VfsPath::new(PhysicalFS::new(p))) + .collect::>(); + + let vfs = OverlayFS::new(&virtual_paths); + let toto: Vec = vfs.read_dir("/home").unwrap().collect(); + println!("{:?}", toto); + println!("{:?}", vfs); + let overlay_root: VfsPath = vfs.into(); + + let output_vpath = VfsPath::new(PhysicalFS::new(output_folder)); + + overlay_root + .copy_dir(&output_vpath) + .expect("Failed to copy the blobs !"); +} diff --git a/src/fs-gen/src/main.rs b/src/fs-gen/src/main.rs index da6e973..c827c2c 100644 --- a/src/fs-gen/src/main.rs +++ b/src/fs-gen/src/main.rs @@ -1,10 +1,21 @@ +use std::{ + path::{Path, PathBuf}, + str::FromStr, +}; + use clap::Parser; -use crate::cli_args::CliArgs; +use crate::{cli_args::CliArgs, image_builder::build_new_image}; mod cli_args; +mod image_builder; fn main() { let args = CliArgs::get_args(); println!("Hello, world!, {:?}", args); + + let paths: Vec = + vec![PathBuf::from_str("../../image-gen/blobs/sha256/layer_1").unwrap()]; + + build_new_image(&paths, &PathBuf::from_str("./titi").unwrap()); }