MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / clone_or_copy_sparse_file

Function clone_or_copy_sparse_file

crates/openshell-driver-vm/src/rootfs.rs:131–154  ·  view source on GitHub ↗
(source: &Path, dest: &Path)

Source from the content-addressed store, hash-verified

129}
130
131pub fn clone_or_copy_sparse_file(source: &Path, dest: &Path) -> Result<(), String> {
132 if let Some(parent) = dest.parent() {
133 fs::create_dir_all(parent).map_err(|e| format!("create {}: {e}", parent.display()))?;
134 }
135 if dest.exists() {
136 fs::remove_file(dest).map_err(|e| format!("remove old file {}: {e}", dest.display()))?;
137 }
138
139 let clone_error = match try_clone_file(source, dest) {
140 Ok(()) => return Ok(()),
141 Err(err) => {
142 let _ = fs::remove_file(dest);
143 err
144 }
145 };
146
147 copy_sparse_file(source, dest).map_err(|copy_error| {
148 format!(
149 "clone {} to {} failed ({clone_error}); sparse copy failed: {copy_error}",
150 source.display(),
151 dest.display()
152 )
153 })
154}
155
156pub fn write_rootfs_image_file(
157 image_path: &Path,

Calls 3

try_clone_fileFunction · 0.85
copy_sparse_fileFunction · 0.85
existsMethod · 0.80