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

Function directory_size_bytes

crates/openshell-driver-vm/src/rootfs.rs:441–457  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

439}
440
441fn directory_size_bytes(path: &Path) -> Result<u64, String> {
442 let metadata =
443 fs::symlink_metadata(path).map_err(|e| format!("stat {}: {e}", path.display()))?;
444 if metadata.file_type().is_file() || metadata.file_type().is_symlink() {
445 return Ok(metadata.len());
446 }
447 if !metadata.file_type().is_dir() {
448 return Ok(0);
449 }
450
451 let mut size = 4096;
452 for entry in fs::read_dir(path).map_err(|e| format!("read {}: {e}", path.display()))? {
453 let entry = entry.map_err(|e| format!("read {}: {e}", path.display()))?;
454 size += directory_size_bytes(&entry.path())?;
455 }
456 Ok(size)
457}
458
459fn round_up_to_mib(bytes: u64) -> u64 {
460 const MIB: u64 = 1024 * 1024;

Callers 2

rootfs_image_size_bytesFunction · 0.85

Calls 2

lenMethod · 0.80
pathMethod · 0.80

Tested by

no test coverage detected