Skip to content

Commit 0bc9489

Browse files
committed
See if we can remove symlinks this way on windows (#301)
1 parent ea561e6 commit 0bc9489

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

git-worktree/src/index/checkout.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub struct PathCache {
3636

3737
mod cache {
3838
use super::PathCache;
39+
use crate::os;
3940
use std::path::{Path, PathBuf};
4041

4142
impl PathCache {
@@ -106,7 +107,7 @@ mod cache {
106107
if !meta.is_dir() {
107108
if self.unlink_on_collision {
108109
if meta.is_symlink() {
109-
symlink::remove_symlink_auto(&self.valid)?;
110+
os::remove_symlink(&self.valid)?;
110111
} else {
111112
std::fs::remove_file(&self.valid)?;
112113
}

git-worktree/src/index/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn try_unlink_path_recursively(path: &Path, path_meta: &std::fs::Metadata) -> st
132132
if path_meta.is_dir() {
133133
std::fs::remove_dir_all(path)
134134
} else if path_meta.is_symlink() {
135-
symlink::remove_symlink_auto(path)
135+
os::remove_symlink(path)
136136
} else {
137137
std::fs::remove_file(path)
138138
}

git-worktree/src/os.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ pub fn remove_symlink(path: &Path) -> io::Result<()> {
1414

1515
#[cfg(windows)]
1616
pub fn remove_symlink(path: &Path) -> io::Result<()> {
17-
symlink::remove_symlink_auto(path)
17+
let meta = std::fs::metadata(path)?;
18+
if meta.is_dir() {
19+
std::fs::remove_dir(path)
20+
} else {
21+
std::fs::remove_file(path)
22+
}
1823
}
1924

2025
#[cfg(windows)]

0 commit comments

Comments
 (0)