From 5b5dc0f4df55a077e583a1af239f88edfcf61a19 Mon Sep 17 00:00:00 2001 From: Warren Hood Date: Tue, 8 Oct 2024 17:52:48 +0200 Subject: [PATCH] Canonicalise paths passed in to profile commands --- mcmpmgr/src/main.rs | 2 +- mcmpmgr/src/profiles.rs | 19 +++++++++++++------ mmm/src/main.rs | 3 ++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mcmpmgr/src/main.rs b/mcmpmgr/src/main.rs index ad2887a..df3d02e 100644 --- a/mcmpmgr/src/main.rs +++ b/mcmpmgr/src/main.rs @@ -484,7 +484,7 @@ async fn main() -> anyhow::Result<()> { instance_directory, } => { let mut userdata = profiles::Data::load()?; - let profile = Profile::new(&instance_directory, pack_source, side); + let profile = Profile::new(&instance_directory, pack_source, side)?; userdata.add_profile(&name, profile); userdata.save()?; println!("Saved profile '{name}'"); diff --git a/mcmpmgr/src/profiles.rs b/mcmpmgr/src/profiles.rs index f728fb6..7e2f12b 100644 --- a/mcmpmgr/src/profiles.rs +++ b/mcmpmgr/src/profiles.rs @@ -26,8 +26,11 @@ impl FromStr for PackSource { let url = s.trim_start_matches("git+").to_string(); Ok(PackSource::Git { url }) } else { - let path = PathBuf::from(s); - Ok(PackSource::Local { path }) + let path = PathBuf::from(s).canonicalize(); + match path { + Ok(path) => Ok(PackSource::Local { path }), + Err(e) => Err(e.to_string()) + } } } } @@ -49,12 +52,16 @@ pub struct Profile { } impl Profile { - pub fn new(instance_folder: &Path, pack_source: PackSource, side: DownloadSide) -> Self { - Self { - instance_folder: instance_folder.into(), + pub fn new( + instance_folder: &Path, + pack_source: PackSource, + side: DownloadSide, + ) -> Result { + Ok(Self { + instance_folder: instance_folder.canonicalize()?, pack_source, side, - } + }) } pub async fn install(&self) -> Result<()> { diff --git a/mmm/src/main.rs b/mmm/src/main.rs index 0c99e5b..f9ce968 100644 --- a/mmm/src/main.rs +++ b/mmm/src/main.rs @@ -84,7 +84,8 @@ impl TryFrom for profiles::Profile { &instance_dir, profiles::PackSource::from_str(&pack_source)?, value.side, - )) + ) + .map_err(|e| e.to_string())?) } }