bulb/src/actions/install.rs
2022-12-01 15:25:08 +01:00

80 lines
2.6 KiB
Rust

use mlua::prelude::*;
use url::Url;
use git2::Repository;
use std::{
sync::{
Mutex,
Arc
}
};
use crate::{
manifest::{
Manifest,
Plugin
},
globals::{
BULB_CACHE_PATH,
MOD_VERSION
},
errors::ErrorWrapper,
State,
Config
};
pub fn install(plugin_name: String, repo_url: Url, /*state_mutex: Arc<Mutex<&State>>,*/ config_mutex: Arc<Mutex<&&mut Config>>) -> LuaResult<()> {
let bulb_cache_path = BULB_CACHE_PATH.lock().unwrap();
let mod_version = *MOD_VERSION.lock().unwrap();
let repo_manifest = Manifest::parse("/home/delta/.config/lite-xl/plugins/bulb/manifest.json", repo_url)?;
//let state = STATE.lock().unwrap();
let config = config_mutex.lock().unwrap();
// If true, the repository isn't cached yet
// if !state.repos.contains(&repo_url) {
// Repository::clone(repo_url.as_str(), bulb_cache_path).map_err(ErrorWrapper)?;
// state.repos.push(repo_url.clone());
// }
// let repo_folder_name = repo_url.path_segments().unwrap().last().unwrap();
// let mut repo_path = bulb_cache_path.clone();
// repo_path.push(repo_folder_name);
// repo_manifest = Manifest::parse(repo_path, repo_url)?;
// repo_manifest = Manifest::parse("/home/delta/.config/lite-xl/plugins/bulb/manifest.json", repo_url)?;
println!("{:#?}", &repo_manifest);
for plugin in repo_manifest.plugins {
println!(".name {}", plugin.name);
println!("_name {}", plugin_name);
if plugin.name == plugin_name {
match plugin.mod_version {
Some(version) => {
if version != mod_version {
return Err(LuaError::external(format!("[bulb] Failed to install plugin \"{}\": mod_version mismatch", plugin_name)));
}
},
_ => {}
}
match plugin.conflicts {
Some(conflicts) => {
for possible_conflict in conflicts.keys() {
for config_plugin in config.plugins.iter() {
println!("{}", &possible_conflict);
println!("{}", config_plugin);
if &possible_conflict == config_plugin {
return Err(LuaError::external(format!("[bulb] Failed to install plugin \"{}\": plugin conflict detected with {}", plugin_name, possible_conflict)));
}
}
}
},
_ => {}
}
}
}
Ok(())
}