Overview
| Artifact ID: | f5651f90c14a845f954afa63a0f9c01854d982d9aad7e9ff114a4a0fad154966 |
|---|---|
| Ticket: | 08203e40e341386c6dc5aac0b8405e506f658656
Windows: [file delete -force] fails on a directory containing a symlink |
| User & Date: | serhiy.storchaka on 2026-10-17 10:51:12 |
Changes
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
On Windows, <nowiki>[file delete -force]</nowiki> fails on a directory that contains a file symbolic link. Tcl itself creates such links: <nowiki>[file link -symbolic]</nowiki> makes a real symlink for a file target since 8.6.11 ([548cd945d6]). This needs administrator rights or Developer Mode, the same as <tt>mklink</tt>. <verbatim> file mkdir d close [open d/a.txt w] file link -symbolic d/b.txt d/a.txt ;# or: mklink d\b.txt a.txt file delete -force d </verbatim> Actual: <tt>error deleting "...": invalid argument</tt>, and <tt>d</tt> stays. Expected: <tt>d</tt> is deleted. Deleting the link itself with <nowiki>[file delete d/b.txt]</nowiki> works. Cause: <tt>TraverseWinTree()</tt> (win/tclWinFCmd.c) hands every reparse point to <tt>TraversalDelete()</tt> as <tt>DOTREE_LINK</tt>, which calls <tt>DoRemoveJustDirectory()</tt> and so <tt>TclWinSymLinkDelete()</tt> (win/tclWinFile.c). That function always passes <tt>IO_REPARSE_TAG_MOUNT_POINT</tt> to <tt>FSCTL_DELETE_REPARSE_POINT</tt>, which fails with a tag mismatch for a symlink (tag <tt>0xA000000C</tt>), giving EINVAL. Even if the reparse data were removed, <tt>RemoveDirectoryW()</tt> cannot remove a file. A directory symlink inside the tree goes through the same code and probably fails the same way. The same function also explains [3c13c4ed31] (<nowiki>[file delete]</nowiki> on a directory symlink fails with "illegal operation on a directory"/"is a directory"), which was closed as Invalid. Possible fix: delete links with <tt>DeleteFileW()</tt> or <tt>RemoveDirectoryW()</tt> depending on <tt>FILE_ATTRIBUTE_DIRECTORY</tt>. Both remove the link and not its target. Related: [972c35d41d] (<nowiki>[file copy]</nowiki> of symlinks), [c8d4f01a54] (NTFS symlinks not supported by <nowiki>[file]</nowiki>). Seen on Windows 11 in 8.6.18, 9.0.5 and 9.1.
- foundin changed to: "8.6.18, 9.0.5, 9.1.0"
- login: "serhiy.storchaka"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- subsystem changed to: "37. File System"
- title changed to:
Windows: [file delete -force] fails on a directory containing a symlink
- type changed to: "Bug"