MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / copy

Method copy

dstack-util/src/system_setup.rs:291–361  ·  view source on GitHub ↗
(host_shared_dir: &Path, host_shared_copy_dir: &Path)

Source from the content-addressed store, hash-verified

289 }
290
291 fn copy(host_shared_dir: &Path, host_shared_copy_dir: &Path) -> Result<HostShared> {
292 const SZ_1KB: u64 = 1024;
293 const SZ_1MB: u64 = 1024 * SZ_1KB;
294
295 let copy = |src: &str, max_size: u64, ignore_missing: bool| -> Result<()> {
296 let src_path = host_shared_dir.join(src);
297 let dst_path = host_shared_copy_dir.join(src);
298 if !src_path.exists() {
299 if ignore_missing {
300 return Ok(());
301 }
302 bail!("Source file {src} does not exist");
303 }
304 let src_size = src_path.metadata()?.len();
305 if src_size > max_size {
306 bail!("Source file {src} is too large, max size is {max_size} bytes");
307 }
308 use fs::os::unix::fs::OpenOptionsExt;
309 let mut src_io = fs::OpenOptions::new()
310 .read(true)
311 .custom_flags(libc::O_NOFOLLOW)
312 .open(src_path)?;
313 let mut dst_io = fs::OpenOptions::new()
314 .write(true)
315 .create(true)
316 .open(dst_path)?;
317 std::io::copy(&mut src_io, &mut dst_io)?;
318 Ok(())
319 };
320 cmd! {
321 info "Mounting host-shared";
322 mkdir -p $host_shared_dir;
323 }?;
324
325 // Try to detect and mount shared disk by label first, fallback to 9p
326 let disk_device = Self::find_disk_by_label(HOST_SHARED_DISK_LABEL);
327 let mounted_via_disk = if let Some(dev) = disk_device {
328 info!("Found shared disk at {}", dev);
329 let mount_result = cmd! {
330 info "Attempting to mount shared disk";
331 mount -o ro $dev $host_shared_dir;
332 };
333 mount_result.is_ok()
334 } else {
335 false
336 };
337
338 if !mounted_via_disk {
339 info!("Shared disk not found, trying 9p virtfs");
340 cmd! {
341 mount -t 9p -o trans=virtio,version=9p2000.L,ro host-shared $host_shared_dir;
342 }?;
343 } else {
344 info!("Successfully mounted shared disk");
345 }
346
347 cmd! {
348 mkdir -p $host_shared_copy_dir;

Callers

nothing calls this directly

Calls 3

createMethod · 0.80
writeMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected