Artifacts Associated With Ticket 08203e
Ticket change [f5651f90c1] (rid 258532) by serhiy.storchaka on 2026-10-17 10:51:12:
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized 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 initialized to: "8.6.18, 9.0.5, 9.1.0"
- login: "serhiy.storchaka"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- subsystem initialized to: "37. File System"
- title initialized to:
Windows: [file delete -force] fails on a directory containing a symlink
- type initialized to: "Bug"
Ticket change [9861d42209] (rid 258627) by serhiy.storchaka on 2026-10-17 14:27:36:
- icomment:
Proposed fix in branch [/timeline?r=win-delete-tree-with-symlinks|win-delete-tree-with-symlinks]: a link to a file is removed like a file, and a link to a directory that is not a junction (<tt>mklink /D</tt>) with <tt>RemoveDirectoryW()</tt>; the targets are not touched. Directory symbolic links inside the tree failed the same way. Tests winFCmd-9.7 and 9.8 (need the right to create symbolic links).
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [1340e057a3] (rid 259538) by serhiy.storchaka on 2026-10-20 18:11:29:
- submitter changed to: "serhiy.storchaka"
Ticket change [29fcdf14f1] (rid 262031) by jan.nijtmans on 2026-11-22 22:58:12:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2461367.4570865394"
- closer changed to: "jan.nijtmans"
- 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.
- icomment:
Merged to [6f1fbfbc88|trunk], core-9-0-branch and core-8-6-branch Many thanks!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"