From 04820ff573a1597d2b94bac62986fd00b1c3fb1b Mon Sep 17 00:00:00 2001 From: Max Howell Date: Mon, 3 Mar 2025 10:36:29 -0500 Subject: [PATCH] wip --- crates/lib/src/install.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/crates/lib/src/install.rs b/crates/lib/src/install.rs index f9fb0c73..658bd904 100644 --- a/crates/lib/src/install.rs +++ b/crates/lib/src/install.rs @@ -1,6 +1,6 @@ use async_compression::tokio::bufread::XzDecoder; use fs2::FileExt; -use std::{error::Error, fs::OpenOptions, path::PathBuf}; +use std::{error::Error, fs::OpenOptions}; use tempfile::tempdir_in; use tokio::task; use tokio_tar::Archive; @@ -13,9 +13,6 @@ use tokio_util::compat::FuturesAsyncReadCompatExt; // futures::io::AsyncRead. use futures::stream::TryStreamExt; -#[cfg(windows)] -use std::os::windows::fs::symlink_dir; - use crate::{ cellar, client::build_client, @@ -40,13 +37,12 @@ where F: FnMut(InstallEvent) + Send + 'static, { let shelf = config.pkgx_dir.join(&pkg.project); - fs::create_dir_all(&shelf)?; + std::fs::create_dir_all(&shelf)?; #[cfg(windows)] let lockfile = OpenOptions::new() .read(true) - .write(true) - .create(true) + .write(true).create(true) .open(shelf.join("lockfile"))?; #[cfg(not(windows))] let lockfile = OpenOptions::new() @@ -114,26 +110,32 @@ where // Step 5: atomically move from temp dir to installation location let partial_path = format!("{}/v{}", pkg.project, pkg.version.raw); - fs::rename(temp_dir.path().join(&partial_path), &dst_path)?; + std::fs::rename(temp_dir.into_path().join(&partial_path), &dst_path)?; let installation = Installation { path: dst_path, pkg: pkg.clone(), }; + #[cfg(not(windows))] symlink(&installation, config).await?; + // ^^ you need admin privs to symlink on windows (wtf) FileExt::unlock(&lockfile)?; Ok(installation) } -use libsemverator::range::Range as VersionReq; -use libsemverator::semver::Semver as Version; -use std::collections::VecDeque; -use std::fs; -use std::path::Path; +#[cfg(not(windows))] +use { + libsemverator::range::Range as VersionReq, + libsemverator::semver::Semver as Version, + std::collections::VecDeque, + std::path::Path, + path::PathBuf +}; +#[cfg(not(windows))] async fn symlink(installation: &Installation, config: &Config) -> Result<(), Box> { let mut versions: VecDeque<(Version, PathBuf)> = cellar::ls(&installation.pkg.project, config) .await? @@ -194,11 +196,13 @@ async fn symlink(installation: &Installation, config: &Config) -> Result<(), Box Ok(()) } +#[cfg(not(windows))] async fn make_symlink( shelf: &Path, symname: &str, installation: &Installation, ) -> Result<(), Box> { + let symlink_path = shelf.join(symname); if symlink_path.is_symlink() { @@ -217,7 +221,7 @@ async fn make_symlink( #[cfg(not(windows))] std::os::unix::fs::symlink(target, &symlink_path)?; #[cfg(windows)] - symlink_dir(target, symlink_path)?; + std::os::windows::fs::symlink_dir(target, symlink_path)?; Ok(()) }