Skip to content

Commit

Permalink
fix(image-builder): use the proper tmp path
Browse files Browse the repository at this point in the history
Signed-off-by: Mathias-Boulay <mathiasboulay@free.fr>
  • Loading branch information
Mathias-Boulay authored and BioTheWolff committed Apr 26, 2024
1 parent 1315469 commit a6c14c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/fs-gen/src/image_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ fn ensure_folder_created(output_folder: &Path) -> Result<()> {
let result = fs::create_dir(output_folder);

// If the file already exists, we're fine
if result.is_err()
&& result
.unwrap_err()
if result.is_err() {
let err = result.unwrap_err();

if err
.raw_os_error()
.is_some_and(|err_val| err_val != FILE_EXISTS_ERROR)
{
return Err(anyhow!("Failed to create folder"));
{
return Err(anyhow!(err)).context(format!(
"Failed to create folder: {}",
output_folder.to_string_lossy()
));
}
}

Ok(())
Expand All @@ -63,24 +68,25 @@ fn ensure_folder_created(output_folder: &Path) -> Result<()> {
/// It works by instantiating an overlay fs via FUSE then copying the files to the desired target
/// # Usage
/// ```
/// merge_layer(vec!["source/layer_1", "source/layer_2"], "/tmp/fused_layers")
/// merge_layer(vec!["source/layer_1", "source/layer_2"], "/tmp/fused_layers", "/tmp")
/// ```
pub fn merge_layer(blob_paths: &[PathBuf], output_folder: &Path) -> Result<()> {
pub fn merge_layer(blob_paths: &[PathBuf], output_folder: &Path, tmp_folder: &Path) -> Result<()> {
// Stack all lower layers
let mut lower_layers = Vec::new();
for lower in blob_paths {
lower_layers.push(Arc::new(new_passthroughfs_layer(&lower.to_string_lossy())?));
}

let mountpoint = Path::new("/tmp/cloudlet_internal");
let binding = tmp_folder.join("overlayfs_mountpoint");
let mountpoint = binding.as_path();
let fs_name = "cloudlet_overlay";

ensure_folder_created(mountpoint)?;
ensure_folder_created(output_folder)?;

// Setup the overlay fs config
let config = Config {
work: "/work".into(),
work: tmp_folder.join("work").to_string_lossy().into(),
mountpoint: output_folder.to_string_lossy().into(),
do_import: true,
..Default::default()
Expand Down
3 changes: 2 additions & 1 deletion src/fs-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ fn main() {
// FIXME: use a subdir of the temp directory instead
let path = Path::new(overlay_subdir.as_path());

merge_layer(&layers_paths, path).expect("Merging layers failed");
merge_layer(&layers_paths, path, &args.temp_directory.clone())
.expect("Merging layers failed");
create_init_file(path);
generate_initramfs(path, Path::new(args.output_file.as_path()));
}
Expand Down

0 comments on commit a6c14c7

Please sign in to comment.