<i>Windows: [file delete -force] on a tree deeper than MAX_PATH returns OK and deletes nothing</i>.
by
.
D 2026-10-17T10:51:12.002
J cmimetype text/x-fossil-wiki
J comment On\sWindows,\s<nowiki>[file\sdelete\s-force]</nowiki>\son\sa\sdirectory\stree\swhose\spaths\sget\slonger\sthan\s<tt>MAX_PATH</tt>\sreturns\swithout\serror\sbut\sdeletes\snothing.\n\n<verbatim>\nset\sbase\s[file\sjoin\s[pwd]\slp]\nset\slong\s[file\sjoin\s$base\s{*}[lrepeat\s4\s[string\srepeat\sX\s254]]]\nfile\smkdir\s$long\nclose\s[open\s$long/leaf.txt\sw]\nfile\sdelete\s-force\s$base\s\s\s\s\s;#\sreturns\s""\s(no\serror)\nfile\sexists\s$base\s\s\s\s\s\s\s\s\s\s\s\s;#\s1,\sall\slevels\sand\sleaf.txt\sare\sstill\sthere\n</verbatim>\n\nExpected:\sthe\stree\sis\sdeleted,\sor\sat\sleast\san\serror\sis\sraised.\sDeleting\sthe\sleaf\sfile\sdirectly\sworks.\n\nCause:\s<tt>TclpObjRemoveDirectory()</tt>\s(win/tclWinFCmd.c)\sconverts\sthe\snormalized\spath\sto\sa\snative\sstring\sby\sitself\swith\s<tt>Tcl_UtfToWCharDString()</tt>,\sso\sit\sdoes\snot\sget\sthe\s<tt>\\\\?\\</tt>\sprefix\sthat\s<tt>TclNativeCreateNativeRep()</tt>\sadds\sabove\s<tt>MAX_PATH</tt>.\s<tt>TraverseWinTree()</tt>\sthen\sappends\scomponents\sto\sthat\sstring.\sOnce\sthe\spath\sis\stoo\slong,\s<tt>GetFileAttributesW()</tt>\sfails\swith\s<tt>ERROR_PATH_NOT_FOUND</tt>\s(ENOENT).\s<tt>FileDeleteCmd()</tt>\s(generic/tclFCmd.c)\streats\sENOENT\safter\sthe\s<tt>lstat()</tt>\sas\s"deleted\sby\ssomeone\selse"\sand\sreturns\sOK.\sThat\scheck\swas\sadded\sin\s[0eb9289e85]\s(first\sreleased\sin\s8.6.9),\sbut\sit\salso\shides\san\sENOENT\sthat\scomes\sfrom\sinside\sthe\srecursive\straversal.\sBefore\s8.6.9\sthe\sdelete\spresumably\sfailed\swith\s"no\ssuch\sfile\sor\sdirectory"\s(not\schecked).\s<nowiki>[file\scopy]</nowiki>\sof\ssuch\sa\stree\salso\suses\s<tt>TraverseWinTree()</tt>\sand\sprobably\sfails\sas\swell\s(not\schecked).\n\nRelated:\s[bc7925fc50]\s(other\slong\spath\sinconsistencies:\s<nowiki>[cd]</nowiki>,\s<nowiki>[glob]</nowiki>,\s<tt>..</tt>)\sand\s[3eace1b21f]\s(<nowiki>[glob]</nowiki>\son\sdeep\spaths).\n\nSeen\son\sWindows\s11\swith\sthe\sdefault\s<tt>LongPathsEnabled=0</tt>\sin\s8.6.18,\s9.0.5\sand\s9.1.\sNot\stested\swith\slong\spaths\senabled.
J foundin 8.6.18,\s9.0.5,\s9.1.0
J login serhiy.storchaka
J priority 5\sMedium
J resolution None
J severity Important
J status Open
J subsystem 37.\sFile\sSystem
J title Windows:\s[file\sdelete\s-force]\son\sa\stree\sdeeper\sthan\sMAX_PATH\sreturns\sOK\sand\sdeletes\snothing
J type Bug
K 076ed602e1774f23ea9619674fd40bb9ab0be43e
U serhiy.storchaka
Z 6c64290821597b82cfc772f35c802390