diff --git a/crates/volta-core/src/fs.rs b/crates/volta-core/src/fs.rs index 0d690391c..2a08c6ac5 100644 --- a/crates/volta-core/src/fs.rs +++ b/crates/volta-core/src/fs.rs @@ -118,17 +118,15 @@ pub fn create_staging_dir() -> Fallible { }) } -/// Copies the file shim -pub fn copy_shim(src: S, dest: D) -> io::Result<()> -where - S: AsRef, - D: AsRef, +/// Create a file symlink. The `dst` path will be a symbolic link pointing to the `src` path. +pub fn symlink_file(src: S, dest: D) -> io::Result<()> + where + S: AsRef, + D: AsRef, { - 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 diff --git a/crates/volta-core/src/shim.rs b/crates/volta-core/src/shim.rs index e2a8c4cad..c6de78263 100644 --- a/crates/volta-core/src/shim.rs +++ b/crates/volta-core/src/shim.rs @@ -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; @@ -71,10 +71,17 @@ pub fn create(shim_name: &str) -> Fallible { 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 {