Canonicalise paths passed in to profile commands

This commit is contained in:
Warren Hood 2024-10-08 17:52:48 +02:00
parent 7afa514783
commit 5b5dc0f4df
3 changed files with 16 additions and 8 deletions

View file

@ -484,7 +484,7 @@ async fn main() -> anyhow::Result<()> {
instance_directory, instance_directory,
} => { } => {
let mut userdata = profiles::Data::load()?; 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.add_profile(&name, profile);
userdata.save()?; userdata.save()?;
println!("Saved profile '{name}'"); println!("Saved profile '{name}'");

View file

@ -26,8 +26,11 @@ impl FromStr for PackSource {
let url = s.trim_start_matches("git+").to_string(); let url = s.trim_start_matches("git+").to_string();
Ok(PackSource::Git { url }) Ok(PackSource::Git { url })
} else { } else {
let path = PathBuf::from(s); let path = PathBuf::from(s).canonicalize();
Ok(PackSource::Local { path }) match path {
Ok(path) => Ok(PackSource::Local { path }),
Err(e) => Err(e.to_string())
}
} }
} }
} }
@ -49,12 +52,16 @@ pub struct Profile {
} }
impl Profile { impl Profile {
pub fn new(instance_folder: &Path, pack_source: PackSource, side: DownloadSide) -> Self { pub fn new(
Self { instance_folder: &Path,
instance_folder: instance_folder.into(), pack_source: PackSource,
side: DownloadSide,
) -> Result<Self> {
Ok(Self {
instance_folder: instance_folder.canonicalize()?,
pack_source, pack_source,
side, side,
} })
} }
pub async fn install(&self) -> Result<()> { pub async fn install(&self) -> Result<()> {

View file

@ -84,7 +84,8 @@ impl TryFrom<ProfileSettings> for profiles::Profile {
&instance_dir, &instance_dir,
profiles::PackSource::from_str(&pack_source)?, profiles::PackSource::from_str(&pack_source)?,
value.side, value.side,
)) )
.map_err(|e| e.to_string())?)
} }
} }