(rootfs: &Path)
| 842 | } |
| 843 | |
| 844 | fn ensure_umoci_binary(rootfs: &Path) -> Result<(), String> { |
| 845 | let path = rootfs.join(SANDBOX_UMOCI_PATH.trim_start_matches('/')); |
| 846 | if UMOCI.is_empty() { |
| 847 | if !path.exists() { |
| 848 | return Err( |
| 849 | "umoci not embedded. Build openshell-driver-vm with OPENSHELL_VM_RUNTIME_COMPRESSED_DIR set and run `mise run vm:setup` first" |
| 850 | .to_string(), |
| 851 | ); |
| 852 | } |
| 853 | } else { |
| 854 | if let Some(parent) = path.parent() { |
| 855 | fs::create_dir_all(parent).map_err(|e| format!("create {}: {e}", parent.display()))?; |
| 856 | } |
| 857 | |
| 858 | let umoci = |
| 859 | zstd::decode_all(Cursor::new(UMOCI)).map_err(|e| format!("decompress umoci: {e}"))?; |
| 860 | fs::write(&path, umoci).map_err(|e| format!("write {}: {e}", path.display()))?; |
| 861 | } |
| 862 | |
| 863 | #[cfg(unix)] |
| 864 | { |
| 865 | use std::os::unix::fs::PermissionsExt as _; |
| 866 | |
| 867 | fs::set_permissions(&path, fs::Permissions::from_mode(0o755)) |
| 868 | .map_err(|e| format!("chmod {}: {e}", path.display()))?; |
| 869 | } |
| 870 | |
| 871 | Ok(()) |
| 872 | } |
| 873 | |
| 874 | fn require_rootfs_path(rootfs: &Path, relative: &str) -> Result<(), String> { |
| 875 | let candidate = rootfs.join(relative.trim_start_matches('/')); |
no test coverage detected