Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Mar 3, 2025
1 parent 5913f24 commit 04820ff
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions crates/lib/src/install.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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<dyn Error>> {
let mut versions: VecDeque<(Version, PathBuf)> = cellar::ls(&installation.pkg.project, config)
.await?
Expand Down Expand Up @@ -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<dyn Error>> {

let symlink_path = shelf.join(symname);

if symlink_path.is_symlink() {
Expand All @@ -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(())
}

0 comments on commit 04820ff

Please sign in to comment.