error deleting: file already exists on Vista
On 2 Windows Vista machines I've tried running file delete -force will sometimes return the error, "error deleting filename: file already exists". This doesn't really make any sense, since of course the file exists or I wouldn't be deleting it. Attached is a script to show the problem and result files from two Vista machines. This is using TCL ActiveState ActiveTcl 8.5.8.0.291595 threaded.
cfac6a1e07Fix [3006571fff]: [file delete -force] of a directory failed with "file already exists" when another process (e.g. a virus scanner or an indexer) kept a file in it open: the file was only marked for deletion, so the directory stayed non-empty for a moment. Retry removing the directory for up to about 1 s. Also use "/" in the whole path of the error message. check-in2026-10-23 10:05:41
File Added - 375021: filedel.tcl
Result of script, Deleted C:/vvv Deleted C:/vvv error deleting "C:/vvv": file already exists error deleting "C:/vvv\foo": permission denied error deleting "C:/vvv\foo": permission denied Deleted C:/vvv Deleted C:/vvv error deleting "C:/vvv": file already exists Deleted C:/vvv error deleting "C:/vvv": file already exists Deleted C:/vvv Deleted C:/vvv Deleted C:/vvv
Also seen sporadically on Win7 64bit dual core machine. Tcl 8.5.5 threaded.
I'm also seeing this on 8.6.0 threaded, on a cifs-mounted filesystem. Workaround here is to retry after several msec.
Reproduced on 8.6, 9.0 and main under Wine, and on Windows 11 on an SMB share, when another process keeps a file in the tree open with FILE_SHARE_DELETE (as virus scanners and indexers do): the file is only marked for deletion, so removing its directory fails with ERROR_DIR_NOT_EMPTY, reported as "file already exists". Local NTFS on Windows 10 1903+ is not affected.
Proposed fix in branch win-delete-retry-not-empty: retry removing the directory for up to about 1 s, as suggested in the comment above. Also the path in the error message now uses "/" only.
Fixed in [trunk], core-9-0-branch and core.8.6.branch
Many thanks!
One closing '}' was placed wrong in your patch. Not a serious deal, but some compilers might still produce a warning on that .... spotted in time.
Attachments:
- filedel.tcl [download] added by pherricoxide on 2010-05-25 01:27:05. [details]