microsoft/openvmm
Publicmirrored fromhttps://github.com/microsoft/openvmmAvailable
flowey/flowey_lib_common/src/_util/mod.rs
45lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | use flowey::node::prelude::FlowPlatformKind; |
| 5 | use flowey::node::prelude::RustRuntimeServices; |
| 6 | use std::path::Path; |
| 7 | |
| 8 | pub mod extract; |
| 9 | pub mod wslpath; |
| 10 | |
| 11 | pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result<()> { |
| 12 | fs_err::create_dir_all(&dst)?; |
| 13 | for entry in fs_err::read_dir(src.as_ref())? { |
| 14 | let entry = entry?; |
| 15 | let dst = dst.as_ref().join(entry.file_name()); |
| 16 | if entry.file_type()?.is_dir() { |
| 17 | copy_dir_all(entry.path(), dst)?; |
| 18 | } else { |
| 19 | fs_err::copy(entry.path(), dst)?; |
| 20 | } |
| 21 | } |
| 22 | Ok(()) |
| 23 | } |
| 24 | |
| 25 | // include a "dummy" _rt argument to enforce that this helper should only be |
| 26 | // used in runtime contexts, and not during flow compile-time. |
| 27 | pub fn running_in_wsl(_rt: &mut RustRuntimeServices<'_>) -> bool { |
| 28 | let Ok(output) = std::process::Command::new("wslpath") |
| 29 | .args(["-aw", "/"]) |
| 30 | .output() |
| 31 | else { |
| 32 | return false; |
| 33 | }; |
| 34 | String::from_utf8_lossy(&output.stdout).starts_with(r"\\wsl.localhost") |
| 35 | } |
| 36 | |
| 37 | /// Returns the name of the bsdtar binary to use. On Windows, this is just the |
| 38 | /// inbox tar.exe. Elsewhere, use bsdtar. This will require installing the |
| 39 | /// libarchive-tools package on Debian-based Linux. |
| 40 | pub fn bsdtar_name(rt: &mut RustRuntimeServices<'_>) -> &'static str { |
| 41 | match rt.platform().kind() { |
| 42 | FlowPlatformKind::Windows => "tar.exe", |
| 43 | FlowPlatformKind::Unix => "bsdtar", |
| 44 | } |
| 45 | } |
| 46 | |