diff --git a/native/XPlatLauncher/Cargo.lock b/native/XPlatLauncher/Cargo.lock index eb715e0101a4..1ad30db9ae31 100644 --- a/native/XPlatLauncher/Cargo.lock +++ b/native/XPlatLauncher/Cargo.lock @@ -1922,16 +1922,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "junction" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca39ef0d69b18e6a2fd14c2f0a1d593200f4a4ed949b240b5917ab51fac754cb" -dependencies = [ - "scopeguard", - "winapi", -] - [[package]] name = "krates" version = "0.15.3" @@ -3690,7 +3680,6 @@ dependencies = [ "cargo-deny", "core-foundation", "jni", - "junction", "libc", "libloading", "log", diff --git a/native/XPlatLauncher/Cargo.toml b/native/XPlatLauncher/Cargo.toml index 22b53041d7b2..ef7dcdd6dd96 100644 --- a/native/XPlatLauncher/Cargo.toml +++ b/native/XPlatLauncher/Cargo.toml @@ -48,8 +48,4 @@ cargo-about = "0.5.7" # generates license report winresource = "0.1.17" [dev-dependencies] -tempfile = "3.8.0" -junction = "1.0.0" - -[features] -symlink_creation = [] \ No newline at end of file +tempfile = "3.8.0" \ No newline at end of file diff --git a/native/XPlatLauncher/build.rs b/native/XPlatLauncher/build.rs index b9cc60743ee4..6c0041f0bd80 100644 --- a/native/XPlatLauncher/build.rs +++ b/native/XPlatLauncher/build.rs @@ -15,8 +15,6 @@ fn main() { fn main_os_specific() { println!("cargo:rustc-link-lib=legacy_stdio_definitions"); - enable_symlinks_if_can_create_them(); - let needs_metadata = std::env::var("XPLAT_LAUNCHER_EMBED_RESOURCES_AND_MANIFEST") .unwrap_or("0".to_string()); @@ -25,37 +23,6 @@ fn main_os_specific() { } } -#[cfg(target_os = "windows")] -fn enable_symlinks_if_can_create_them() { - let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); - let target = out_dir.join("target"); - if target.exists() { - std::fs::remove_file(&target) - .expect("Failed to delete target file") - } - - let contents = "test"; - std::fs::write(&target, contents) - .expect("Unable to write to target file"); - - let link = out_dir.join("link"); - if link.exists() { - // DeleteFile removes the symlink, and that's what is used - std::fs::remove_file(&link) - .expect("Failed to delete the link") - } - - match std::os::windows::fs::symlink_file(&target, &link) { - Ok(_) => allow_symlink_creation(), - Err(e) if e.raw_os_error() == Some(1314) => { - println!( - "Cannot use CreateSymbolicLink API, will use junction instead. File link creation will result in runtime errors." - ); - }, - Err(e) => panic!("Failed to create symbolic link, but not due to the privileges: {:?}", e), - } -} - #[cfg(target_os = "windows")] fn embed_metadata() { let cargo_root_env_var = std::env::var("CARGO_MANIFEST_DIR").unwrap(); @@ -74,11 +41,5 @@ fn embed_metadata() { res.compile().expect("Failed to embed resource table and/or application manifest"); } -fn allow_symlink_creation() { - println!("cargo:rustc-cfg=feature=\"symlink_creation\""); -} - #[cfg(not(target_os = "windows"))] -fn main_os_specific() { - allow_symlink_creation() -} \ No newline at end of file +fn main_os_specific() { } \ No newline at end of file diff --git a/native/XPlatLauncher/tests/utils/mod.rs b/native/XPlatLauncher/tests/utils/mod.rs index 6b6ea6d309e3..ab9539f43d0b 100644 --- a/native/XPlatLauncher/tests/utils/mod.rs +++ b/native/XPlatLauncher/tests/utils/mod.rs @@ -384,26 +384,20 @@ fn symlink(original: &Path, link: &Path) -> Result<()> { } #[cfg(target_os = "windows")] -#[cfg(feature = "symlink_creation")] fn symlink(original: &Path, link: &Path) -> Result<()> { - if original.is_dir() { - std::os::windows::fs::symlink_dir(original, link) - } else { - std::os::windows::fs::symlink_file(original, link) - } - .with_context(|| format!("Failed to create symlink {link:?} pointing to {original:?}")) -} + let result = match original.is_dir() { + true => std::os::windows::fs::symlink_dir(original, link), + false => std::os::windows::fs::symlink_file(original, link) + }; -#[cfg(target_os = "windows")] -#[cfg(not(feature = "symlink_creation"))] -fn symlink(original: &Path, link: &Path) -> Result<()> { - if (original.is_file()) { - bail!("symlink_creation feature is not enabled, can not use CreateSymbolicLink.\ - Consider having a privilege to do that or enabling Developer Mode"); - } + let message = match &result { + Ok(_) => "", + Err(e) if e.raw_os_error() == Some(1314) => "can not use CreateSymbolicLink.\ + Consider having a privilege to do that or enabling Developer Mode", + Err(_) => "failed to create symlink, but not due to privileges", + }; - junction::create(original, link) - .with_context(|| format!("Failed to create symlink {link:?} pointing to {original:?}")) + result.with_context(|| format!("Failed to create symlink {link:?} pointing to {original:?}; {message}")) } pub fn get_custom_config_dir() -> PathBuf {