Skip to content

Commit b5b15e0

Browse files
committed
os.unlink can remove junctions on windows
1 parent 68af202 commit b5b15e0

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

vm/src/stdlib/os.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,17 @@ mod _os {
437437
#[pyfunction]
438438
fn remove(path: PyPathLike, dir_fd: DirFd, vm: &VirtualMachine) -> PyResult<()> {
439439
let path = make_path(vm, &path, &dir_fd)?;
440-
fs::remove_file(path).map_err(|err| err.into_pyexception(vm))
440+
let is_junction = cfg!(windows)
441+
&& fs::symlink_metadata(path).map_or(false, |meta| {
442+
let ty = meta.file_type();
443+
ty.is_dir() && ty.is_symlink()
444+
});
445+
let res = if is_junction {
446+
fs::remove_dir(path)
447+
} else {
448+
fs::remove_file(path)
449+
};
450+
res.map_err(|err| err.into_pyexception(vm))
441451
}
442452

443453
#[pyfunction]

0 commit comments

Comments
 (0)