Skip to content

Commit fd85021

Browse files
committed
replace fs::copy by calling cp to support sparse files
Some images are sparse files and fs::copy doesn't support sparse files[1]. This causes the image to be inflated and the copy to take very long which is not what we want. [1] rust-lang/rust#55909
1 parent 5641e17 commit fd85021

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,11 @@ async fn customize_image(image_uri: &str, image_format: &str, package_name: &str
366366
} else {
367367
// Treat as local file path, copy to image_path
368368
println!("Using local image file: {}", image_uri);
369-
fs::copy(image_uri, &image_path)
370-
.with_context(|| format!("Failed to copy local image file from {}", image_uri))?;
369+
run_command(
370+
"cp",
371+
&[image_uri, image_path.to_str().unwrap()],
372+
&format!("Failed to copy local image file from {}", image_uri),
373+
)?;
371374
}
372375

373376
let release: String;
@@ -417,8 +420,11 @@ async fn customize_image(image_uri: &str, image_format: &str, package_name: &str
417420
restore_dns(&rootfs_dir)?;
418421
} // `cleanup_guard` is dropped here, triggering cleanup
419422

420-
fs::copy(&image_path, &final_image_path)
421-
.context("Failed to copy image to current directory")?;
423+
run_command(
424+
"cp",
425+
&[image_path.to_str().unwrap(), final_image_path.to_str().unwrap()],
426+
"Failed to copy final image.",
427+
)?;
422428

423429
Ok(ImageInfo {
424430
image_path: final_image_path,

0 commit comments

Comments
 (0)