|
2026-10-20
| ||
| 18:11 | • Ticket [076ed602e1] Windows: file delete -force on a tree deeper than MAX_PATH... artifact: f30d3bb3ba user: serhiy.storchaka | |
|
2026-10-17
| ||
| 14:06 | • Ticket [076ed602e1]: 3 changes artifact: 490dc21048 user: serhiy.storchaka | |
| 14:04 | Fix [076ed602e1]: on Windows, [file delete -force] on a tree deeper than MAX_PATH returned OK and de... check-in: d96491196f user: serhiy.storchaka tags: win-delete-long-path | |
| 10:51 | • New ticket [076ed602e1] Windows: file delete -force on a tree deeper than MAX_... artifact: e168ed7b6d user: serhiy.storchaka | |
Windows: [file delete -force] on a tree deeper than MAX_PATH returns OK and deletes nothing
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
Expected: the tree is deleted, or at least an error is raised. Deleting the leaf file directly works.
Cause: TclpObjRemoveDirectory() (win/tclWinFCmd.c) converts the normalized path to a native string by itself with Tcl_UtfToWCharDString(), so it does not get the \\?\ prefix that TclNativeCreateNativeRep() adds above MAX_PATH. TraverseWinTree() then appends components to that string. Once the path is too long, GetFileAttributesW() fails with ERROR_PATH_NOT_FOUND (ENOENT). FileDeleteCmd() (generic/tclFCmd.c) treats ENOENT after the lstat() 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). [file copy] of such a tree also uses TraverseWinTree() and probably fails as well (not checked).
Related: [bc7925fc50] (other long path inconsistencies: [cd], [glob], ..) and [3eace1b21f] ([glob] on deep paths).
Seen on Windows 11 with the default LongPathsEnabled=0 in 8.6.18, 9.0.5 and 9.1. Not tested with long paths enabled.
d96491196fFix [076ed602e1]: on Windows, [file delete -force] on a tree deeper than MAX_PATH returned OK and deleted nothing. Use the extended path prefix for the recursive delete. Also go on with the rest of the tree when an entry is deleted by someone else meanwhile (also when its deletion is pending), instead of stopping and leaving the tree behind. check-in2026-10-17 14:04:57
Proposed fix in branch win-delete-long-path: the recursive delete uses the extended path prefix \\?\, so the paths inside the tree can exceed MAX_PATH. It also no longer stops at an entry that someone else deleted meanwhile (or whose deletion is pending), which left the rest of the tree behind while [file delete] returned OK. Tests winFCmd-9.5 and 9.6.