microsoft/openvmm

Public

mirrored fromhttps://github.com/microsoft/openvmmAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
release/2411-fork

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

flowey/flowey_lib_common/src/_util/mod.rs

45lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use flowey::node::prelude::FlowPlatformKind;
5use flowey::node::prelude::RustRuntimeServices;
6use std::path::Path;
7
8pub mod extract;
9pub mod wslpath;
10
11pub 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.
27pub 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.
40pub 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