From 92c78648df99b0e22865d29b4ea3da6ba107dd7f Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Sun, 26 Apr 2026 13:59:13 -0400 Subject: [PATCH 1/2] Don't perform an existence check in `get_target` Signed-off-by: William Woodruff --- src/internals.rs | 4 ---- src/lib.rs | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/internals.rs b/src/internals.rs index 188574f1..b52090e4 100644 --- a/src/internals.rs +++ b/src/internals.rs @@ -129,10 +129,6 @@ pub fn exists(junction: &Path) -> io::Result { } pub fn get_target(junction: &Path) -> io::Result { - // MSRV(1.63): use Path::try_exists instead - if !junction.exists() { - return Err(io::Error::new(io::ErrorKind::NotFound, "`junction` does not exist")); - } let file = helpers::open_reparse_point(junction, false)?; let mut data = BytesAsReparseDataBuffer::new(); helpers::get_reparse_data_point(file.as_raw_handle(), data.as_mut_ptr())?; diff --git a/src/lib.rs b/src/lib.rs index 8552d9b6..4293878a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -99,6 +99,8 @@ pub fn exists>(junction: P) -> io::Result { /// Gets the target of the specified junction point. /// +/// This returns the target path of the junction point, even if the target does not exist. +/// /// N.B. Only works on NTFS. /// /// # Example From 2069014547affa9461e0ea1526be4a44895df98e Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Sun, 26 Apr 2026 14:09:41 -0400 Subject: [PATCH 2/2] Add a testcase for the changed behavior Signed-off-by: William Woodruff --- src/tests.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tests.rs b/src/tests.rs index d03ff643..76b52a82 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -251,6 +251,20 @@ fn get_target_user_dirs() { } } +#[test] +fn get_target_target_no_exist() { + let tmpdir = create_tempdir(); + + let target = tmpdir.path().join("target"); + let junction = tmpdir.path().join("junction"); + + super::create(&target, &junction).unwrap(); + match super::get_target(&junction) { + Ok(t) => assert_eq!(t, target), + other => panic!("get_target should succeed when target does not exist: {:?}", other), + } +} + #[test] fn create_with_verbatim_prefix_paths() { // Regression test for https://github.com/tesuji/junction/issues/30