[Buildbot] #2885: Windows: rmdirRecursive() fails if a contained file is opened
Buildbot trac
trac at buildbot.net
Thu Sep 11 09:27:50 UTC 2014
#2885: Windows: rmdirRecursive() fails if a contained file is opened
--------------------+------------------------
Reporter: dl | Owner:
Type: defect | Status: new
Priority: major | Milestone: undecided
Version: 0.8.9 | Resolution:
Keywords: windows |
--------------------+------------------------
Comment (by dl):
Here are my thoughts about https://github.com/buildbot/buildbot/pull/540:
* `rmdir` works as expected (Windows 7), when the directory to be
removed contains read-only files.
* `rmdir` and `rmdirRecursive()` take approximately the same time to
delete a large directory.
* `rmdir` fails (Windows 7) with a meaningful message, when the
directory to be removed contains opened files:
path\to\file - Der Prozess kann nicht auf die Datei zugreifen, da
sie von einem anderen Prozess verwendet wird.
It removes all files and directories it can and reports all the
others.
* However, there seems to be no waiting/repeating involved and I could
not find any documentation how delayed deletes are handled.
In fact, https://github.com/buildbot/buildbot/pull/540 calls `rmdir`
again if the first try fails - this suggests that delayed delete can cause
`rmdir` to fail.
See also http://superuser.com/questions/537757/completely-delete-a
-folder-in-windows-using-command-line.
* Looking at `rmdir` of Windows 7 with API Monitor shows:
- It uses `FindFirstFileW()`, `FindNextFileW()` to iterate over
the files/directories
- If a file has the attribute `FILE_ATTRIBUTE_READONLY`, it removes
it with `SetFileAttributesW()`
- It uses `DeleteFileW()`/`RemoveDirectoryW()` to delete files and
directories
So, I cannot see any magic involved here either.
It looks to me, that using `rmdir` over `rmdirRecursive()` does at
most mitigate the problem but not solve it.
* The change addresses only native Windows, but the problem occurs on
Cygwin too.
* Calling `rmdir` as an external program involves the entire Windows
escaping hell, as paths have to be passed as commandline arguments.
An escaping error together with `rmdir` can cause a catastrophic
failure.
In test scripts I do not see much testing of the escaping for Windows.
Maybe it was tested thoroughly, but if not, it should not be used for
"dangerous" commands.
Personally, I would prefer a Pythonic solution (without calling external
binaries) and more thorough (scripted) testing of Windows specific code.
Maybe in future Python version we see a better `shutil.rmtree` anyway.
--
Ticket URL: <http://trac.buildbot.net/ticket/2885#comment:5>
Buildbot <http://buildbot.net/>
Buildbot: build/test automation
More information about the bugs
mailing list