Skip to content

Commit

Permalink
Use shim copy only for Windows and revert it for unix
Browse files Browse the repository at this point in the history
  • Loading branch information
rcsilva83 committed Oct 27, 2023
1 parent 25a14e2 commit b924dc0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
18 changes: 8 additions & 10 deletions crates/volta-core/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,15 @@ pub fn create_staging_dir() -> Fallible<TempDir> {
})
}

/// Copies the file shim
pub fn copy_shim<S, D>(src: S, dest: D) -> io::Result<()>
where
S: AsRef<Path>,
D: AsRef<Path>,
/// Create a file symlink. The `dst` path will be a symbolic link pointing to the `src` path.
pub fn symlink_file<S, D>(src: S, dest: D) -> io::Result<()>
where
S: AsRef<Path>,
D: AsRef<Path>,
{
let result = std::fs::copy(src, dest);
match result {
Ok(_v) => Ok(()),
Err(e) => Err(e),
}
return std::os::windows::fs::symlink_file(src, dest);

return std::os::unix::fs::symlink(src, dest);
}

/// Create a directory symlink. The `dst` path will be a symbolic link pointing to the `src` path
Expand Down
13 changes: 10 additions & 3 deletions crates/volta-core/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io;
use std::path::Path;

use crate::error::{Context, ErrorKind, Fallible, VoltaError};
use crate::fs::{copy_shim, read_dir_eager};
use crate::fs::{read_dir_eager, symlink_file};
use crate::layout::{volta_home, volta_install};
use crate::sync::VoltaLock;
use log::debug;
Expand Down Expand Up @@ -70,10 +70,17 @@ pub fn create(shim_name: &str) -> Fallible<ShimResult> {
let executable = volta_install()?.shim_executable();
let shim = volta_home()?.shim_file(shim_name);

let shim_result;
#[cfg(windows)]
windows::create_git_bash_script(shim_name)?;
{
windows::create_git_bash_script(shim_name)?;
shim_result = std::fs::copy(executable, shim);
}

#[cfg(unix)]
shim_result = symlink_file(executable, shim);

match copy_shim(executable, shim) {
match shim_result {
Ok(_) => Ok(ShimResult::Created),
Err(err) => {
if err.kind() == io::ErrorKind::AlreadyExists {
Expand Down

0 comments on commit b924dc0

Please sign in to comment.