|
|
@ -11,43 +11,31 @@ use super::error::MapperResult;
|
|
|
|
|
|
|
|
|
|
|
|
struct NodeApp {
|
|
|
|
struct NodeApp {
|
|
|
|
info: DirEntry,
|
|
|
|
info: DirEntry,
|
|
|
|
|
|
|
|
name: String,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl NodeApp {
|
|
|
|
impl NodeApp {
|
|
|
|
pub fn new(info: DirEntry) -> Self {
|
|
|
|
pub fn new(info: DirEntry) -> Self {
|
|
|
|
Self { info }
|
|
|
|
let path = info.path();
|
|
|
|
}
|
|
|
|
let name = path.file_stem().unwrap();
|
|
|
|
|
|
|
|
let name = name.to_string_lossy().into_owned();
|
|
|
|
|
|
|
|
|
|
|
|
/// returns the name of the application
|
|
|
|
Self { info, name }
|
|
|
|
pub fn name(&self) -> String {
|
|
|
|
|
|
|
|
let name = self.info.file_name();
|
|
|
|
|
|
|
|
name.to_string_lossy().into_owned()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn unmap(&self) -> MapperResult<()> {
|
|
|
|
pub fn name(&self) -> &String {
|
|
|
|
fs::remove_file(self.info.path()).await?;
|
|
|
|
&self.name
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// creates wrappers to map this application
|
|
|
|
/// creates wrappers to map this application
|
|
|
|
pub async fn map_executable(&self) -> MapperResult<()> {
|
|
|
|
pub async fn map_executable(&self) -> MapperResult<()> {
|
|
|
|
let src_path = BIN_DIR.join(self.info.file_name());
|
|
|
|
let src_path = BIN_DIR.join(self.info.file_name());
|
|
|
|
let name = self.info.file_name();
|
|
|
|
self.write_wrapper_script(&src_path).await
|
|
|
|
let name = name.to_string_lossy();
|
|
|
|
|
|
|
|
self.write_wrapper_script(&name, &src_path).await
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
|
|
#[cfg(not(target_os = "windows"))]
|
|
|
|
async fn write_wrapper_script(&self, name: &str, path: &Path) -> MapperResult<()> {
|
|
|
|
async fn write_wrapper_script(&self, path: &Path) -> MapperResult<()> {
|
|
|
|
fs::write(
|
|
|
|
fs::write(path, format!("#!/bin/sh\nnenv exec {} \"$@\"", self.name)).await?;
|
|
|
|
path,
|
|
|
|
|
|
|
|
format!(
|
|
|
|
|
|
|
|
r#"#!/bin/sh
|
|
|
|
|
|
|
|
nenv exec {name} "$@""#
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
let src_metadata = self.info.metadata().await?;
|
|
|
|
let src_metadata = self.info.metadata().await?;
|
|
|
|
fs::set_permissions(&path, src_metadata.permissions()).await?;
|
|
|
|
fs::set_permissions(&path, src_metadata.permissions()).await?;
|
|
|
|
|
|
|
|
|
|
|
@ -55,8 +43,13 @@ impl NodeApp {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
async fn write_wrapper_script(&self, name: &str, path: &Path) -> MapperResult<()> {
|
|
|
|
async fn write_wrapper_script(&self, path: &Path) -> MapperResult<()> {
|
|
|
|
fs::write(path, format!("nenv exec {name} %*")).await?;
|
|
|
|
fs::write(
|
|
|
|
|
|
|
|
path.with_extension("bat"),
|
|
|
|
|
|
|
|
format!("nenv exec {} %*", self.name),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
let src_metadata = self.info.metadata().await?;
|
|
|
|
fs::set_permissions(&path, src_metadata.permissions()).await?;
|
|
|
|
fs::set_permissions(&path, src_metadata.permissions()).await?;
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
@ -64,19 +57,17 @@ impl NodeApp {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn map_node_bin(node_path: NodePath) -> MapperResult<()> {
|
|
|
|
pub async fn map_node_bin(node_path: NodePath) -> MapperResult<()> {
|
|
|
|
let applications = get_applications(&node_path.bin()).await?;
|
|
|
|
let mapped_app_names = get_applications(&*BIN_DIR)
|
|
|
|
let mapped_applications = get_applications(&*BIN_DIR).await?;
|
|
|
|
.await?
|
|
|
|
let mut new_mapped = HashSet::new();
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.map(NodeApp::name)
|
|
|
|
|
|
|
|
.cloned()
|
|
|
|
|
|
|
|
.collect::<HashSet<_>>();
|
|
|
|
|
|
|
|
|
|
|
|
for application in applications {
|
|
|
|
let mut applications = get_applications(&node_path.bin()).await?;
|
|
|
|
application.map_executable().await?;
|
|
|
|
applications.retain(|app| !mapped_app_names.contains(app.name()));
|
|
|
|
new_mapped.insert(application.name());
|
|
|
|
|
|
|
|
}
|
|
|
|
futures::future::join_all(applications.iter().map(NodeApp::map_executable)).await;
|
|
|
|
for app in mapped_applications {
|
|
|
|
|
|
|
|
if !new_mapped.contains(&app.name()) {
|
|
|
|
|
|
|
|
app.unmap().await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|