Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 29fcdf14f1d764382e0ef56f84f8b5ae87da959a94bf3ac6c5a1ac56738b890b
Ticket: 08203e40e341386c6dc5aac0b8405e506f658656
Windows: [file delete -force] fails on a directory containing a symlink
User & Date: jan.nijtmans on 2026-11-22 22:58:12
Changes

  1. assignee changed to: "jan.nijtmans"
  2. closedate changed to: "2461367.4570865394"
  3. closer changed to: "jan.nijtmans"
  4. 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.
    
  5. icomment:
    Merged to [6f1fbfbc88|trunk], core-9-0-branch and core-8-6-branch
    
    Many thanks!
    
  6. login: "jan.nijtmans"
  7. mimetype: "text/x-fossil-wiki"
  8. resolution changed to: "Fixed"
  9. status changed to: "Closed"