You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fs::Dir::remove_file and remove_dir remove the target of a symlink on Windows #164249
#![feature(dirfd)]use std::fs::{self,Dir};use std::os::windows::fs::{symlink_dir, symlink_file};fnexists(path:&str) -> bool{
fs::symlink_metadata(path).is_ok()}fnmain() -> std::io::Result<()>{
fs::create_dir("d")?;
fs::write("d/target.txt",b"data")?;
fs::create_dir("d/targetdir")?;symlink_file("target.txt","d/filelink")?;symlink_dir("targetdir","d/dirlink")?;let dir = Dir::open("d")?;println!("Dir::remove_file(filelink) = {:?}", dir.remove_file("filelink"));println!(" filelink exists: {}", exists("d/filelink"));println!(" target.txt exists: {}", exists("d/target.txt"));println!("Dir::remove_dir(dirlink) = {:?}", dir.remove_dir("dirlink"));println!(" dirlink exists: {}", exists("d/dirlink"));println!(" targetdir exists: {}", exists("d/targetdir"));// For comparison: the same on a fresh setup with the path-based functions.
fs::create_dir("e")?;
fs::write("e/target.txt",b"data")?;symlink_file("target.txt","e/filelink")?;println!("fs::remove_file(filelink) = {:?}", fs::remove_file("e/filelink"));println!(" filelink exists: {}", exists("e/filelink"));println!(" target.txt exists: {}", exists("e/target.txt"));Ok(())}
I expected to see this happen: the Dir methods remove the link and leave its target alone. That is what they do on Unix, and what fs::remove_file does on Windows (the third case below).
Instead, this happened: the link stays and its target is removed.
Activity
rustbot commentedon Oct 13, 2026
Error: Only Rust team members can ping teams.
Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.
Rollup merge of rust-lang#164559 - RalfJung:dir-remove-rename-symlink…
Rollup merge of rust-lang#164559 - RalfJung:dir-remove-rename-symlink…
Rollup merge of rust-lang#164559 - RalfJung:dir-remove-rename-symlink…
Rollup merge of rust-lang#164559 - RalfJung:dir-remove-rename-symlink…
Rollup merge of rust-lang#164559 - RalfJung:dir-remove-rename-symlink…
Unrolled build for #164559 in rollup 165760
Rollup merge of #164559 - RalfJung:dir-remove-rename-symlinks, r=Chri…
Rollup merge of #164559 - RalfJung:dir-remove-rename-symlinks, r=Chri…