Skip to content

Commit e4b9328

Browse files
committed
os.remove can remove junctions on windows
1 parent 3d0311c commit e4b9328

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/test/support/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ def _waitfor(func, pathname, waitall=False):
372372
# Increase the timeout and try again
373373
time.sleep(timeout)
374374
timeout *= 2
375+
print("ooh there's still", L)
375376
warnings.warn('tests may fail, delete still pending for ' + pathname,
376377
RuntimeWarning, stacklevel=4)
377378

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::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)