Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e168ed7b6de9b73ead5708470539edecd881dfd23e71a5853b9947bc5c50b007
Ticket: 076ed602e1774f23ea9619674fd40bb9ab0be43e
Windows: [file delete -force] on a tree deeper than MAX_PATH returns OK and deletes nothing
User & Date: serhiy.storchaka on 2026-10-17 10:51:12
Changes

  1. cmimetype changed to: "text/x-fossil-wiki"
  2. comment changed to:
    On Windows, <nowiki>[file delete -force]</nowiki> on a directory tree whose paths get longer than <tt>MAX_PATH</tt> returns without error but deletes nothing.
    
    <verbatim>
    set base [file join [pwd] lp]
    set long [file join $base {*}[lrepeat 4 [string repeat X 254]]]
    file mkdir $long
    close [open $long/leaf.txt w]
    file delete -force $base     ;# returns "" (no error)
    file exists $base            ;# 1, all levels and leaf.txt are still there
    </verbatim>
    
    Expected: the tree is deleted, or at least an error is raised. Deleting the leaf file directly works.
    
    Cause: <tt>TclpObjRemoveDirectory()</tt> (win/tclWinFCmd.c) converts the normalized path to a native string by itself with <tt>Tcl_UtfToWCharDString()</tt>, so it does not get the <tt>\\?\</tt> prefix that <tt>TclNativeCreateNativeRep()</tt> adds above <tt>MAX_PATH</tt>. <tt>TraverseWinTree()</tt> then appends components to that string. Once the path is too long, <tt>GetFileAttributesW()</tt> fails with <tt>ERROR_PATH_NOT_FOUND</tt> (ENOENT). <tt>FileDeleteCmd()</tt> (generic/tclFCmd.c) treats ENOENT after the <tt>lstat()</tt> as "deleted by someone else" and returns OK. That check was added in [0eb9289e85] (first released in 8.6.9), but it also hides an ENOENT that comes from inside the recursive traversal. Before 8.6.9 the delete presumably failed with "no such file or directory" (not checked). <nowiki>[file copy]</nowiki> of such a tree also uses <tt>TraverseWinTree()</tt> and probably fails as well (not checked).
    
    Related: [bc7925fc50] (other long path inconsistencies: <nowiki>[cd]</nowiki>, <nowiki>[glob]</nowiki>, <tt>..</tt>) and [3eace1b21f] (<nowiki>[glob]</nowiki> on deep paths).
    
    Seen on Windows 11 with the default <tt>LongPathsEnabled=0</tt> in 8.6.18, 9.0.5 and 9.1. Not tested with long paths enabled.
    
  3. foundin changed to: "8.6.18, 9.0.5, 9.1.0"
  4. login: "serhiy.storchaka"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. severity changed to: "Important"
  8. status changed to: "Open"
  9. subsystem changed to: "37. File System"
  10. title changed to:
    Windows: [file delete -force] on a tree deeper than MAX_PATH returns OK and deletes nothing
    
  11. type changed to: "Bug"