1#![expect(missing_docs)]
5#![forbid(unsafe_code)]
6
7use flowey_core::pipeline::IntoPipeline;
8use std::path::Path;
9
10mod cli;
11mod flow_resolver;
12mod pipeline_resolver;
13mod var_db;
14
15pub fn flowey_main<ProjectPipelines: clap::Subcommand + IntoPipeline>(
17 flowey_crate: &str,
18 repo_root: &Path,
19) -> ! {
20 if let Err(e) = cli::cli_main::<ProjectPipelines>(flowey_crate, repo_root) {
21 log::error!("Error: {:#}", e);
22 std::process::exit(-1);
23 } else {
24 std::process::exit(0)
25 }
26}
27
28pub fn running_in_wsl() -> bool {
30 let Ok(output) = std::process::Command::new("wslpath")
31 .args(["-aw", "/"])
32 .output()
33 else {
34 return false;
35 };
36 String::from_utf8_lossy(&output.stdout).starts_with(r"\\wsl.localhost")
37}
38
39pub fn is_wsl_windows_path(path: &Path) -> bool {
53 if !running_in_wsl() {
54 return false;
55 }
56
57 let path = match std::path::absolute(path) {
58 Ok(p) => p,
59 Err(_) => return false,
60 };
61
62 let mounts = match std::fs::read_to_string("/proc/mounts") {
64 Ok(m) => m,
65 Err(_) => return false,
66 };
67
68 let drvfs_mount_points: Vec<String> = mounts
69 .lines()
70 .filter_map(|line| {
71 let parts: Vec<&str> = line.split_whitespace().collect();
72 if parts.len() >= 4 {
73 let mount_point = parts[1];
74 let fs_type = parts[2];
75 let mount_options = parts[3];
76 if fs_type == "9p" && mount_options.contains("aname=drvfs") {
78 return Some(mount_point.to_string());
79 }
80 }
81 None
82 })
83 .collect();
84
85 let path_str = path.to_string_lossy();
86
87 for mount_point in &drvfs_mount_points {
89 let mount_point_normalized = mount_point.trim_end_matches('/');
90 if path_str == mount_point_normalized
91 || path_str.starts_with(&format!("{}/", mount_point_normalized))
92 {
93 return true;
94 }
95 }
96
97 false
98}