-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FilePath.setContent should do an atomic rename on Windows where possible #3004
Comments
I don't think there could be a For the particular case where |
Replying to exarkun:
I was referring to the case that you refer to here:
On other platforms, or in the case where we have an atomic rename on Windows (the APIs I referred to don't clearly describe their error behavior) it would simply delete any temporary files that were created by not finished. The important thing is that you could call this method on a directory without necessarily understanding the steps involved in |
|
Replying to davidsarah:
If it did use pywin32, it would be an optional dependency, falling back to the current behavior. The advantage of pywin32 is that you get 64-bit support for free, and it's somebody else's job to make sure it doesn't segfault. Thanks for the info though, and I look forward to your ctypes-using patch :). |
pywin32 is already a fairly significant dependency on Windows. I think we should depend on it if we are going to provide this functionality. "Atomic update, unless you (or a naive end user) forgot to install a dependency" seems like very unuseful behavior to offer in this API. |
For context, we recently succeeded at eliminating pywin32 from the dependencies of Tahoe-LAFS, allowing us to remove instructions to our users to manually install pywin32 if they are on Windows. This is very important to me—it has taken about five years, and we've gradually eliminated every instruction to manually install a dependency other than Python. pywin32 was the last one to go. This was possible because David-Sarah wrote code using ctypes to do what we previously used pywin32 for. (And, unfortunately, because we changed to use For Tahoe-LAFS's purposes, I would rather suffer an unreliable |
Replying to zooko:
So if pywin32 fixed this bug, your objection would go away?
This strikes me as a bad tradeoff. Am I wrong that the choice is writing a bunch of new code vs. setting up an alternative distribution name on PyPI for pywin32 with a metadata pointer at the correct files, and then declaring it as a dependency? Presumably such a fork would motivate the actual pywin32 maintainers to add a step to their release process, or give you the relevant credentials. But, I wouldn't reject a ctypes-based implementation out of hand; ctypes is always available and the relevant APIs are all system-level things that shouldn't change much, so by all means submit a patch :).
If you really want to avoid the possibility of a future required dependency on pywin32, we should probably have a Twisted buildbot without it installed. Would you like to supply or maintain one? This may be a little tricky, because Buildbot itself requires parts of Twisted that need pywin32; the Python environments would need to be isolated from each other. Ideally you could just fix the issue with pywin32's installation though, and skip this whole mess :). |
Replying to glyph:
I had forgotten that I almost got that working in 2009! Yes, my objection is all about installation. I should definitely try to replicate my success from that comment from 2009. I'm not sure what exactly would be required to make it work for us. Ideally doing
Here is a ticket about testing, on the Tahoe-LAFS buildbot, that Tahoe-LAFS doesn't depend on Here is a ticket about testing, on the Twisted buildbot, that Twisted doesn't depend on any packages which aren't declared in a machine-parseable format in the Twisted packaging metadata: #4438 . Currently that ticket is closed as |
The |
Upstream issue has been moved to mhammond/pywin32#334
Relevant: mhammond/pywin32#2208 |
Thanks for update. I think that win32 API is no longer an issue. Stdlib should be good enough. I think that with modern python (3.3 and newer) we can use The current code uses twisted/src/twisted/python/filepath.py Lines 1572 to 1577 in 087afb8
Looking at the Python source code, I can see that |
It would really be helpful to have someone who knows a lot of Windows stuff look at this ticket and figure out what the right thing to do is.
Using the python stdlib's default os.rename, the right thing to do would be to prefer ending up in a more-consistent state. Currently
setContent
will delete the old file before moving the new file into place. It might also be advisable to have a "repair" method to complete setContent operations which died after the file was written but before it was moved into place. This should be a separate ticket since UNIX can leave extraneous temporary files around too, but whether it needs to differ per platform depends on whether we can use this:It looks like the MoveFileWithProgress (or
MoveFileEx
, or evenMoveFileTransacted
on Vista) may provide an atomic-rename facility. If we can invoke these without external dependencies it might be better to forego the use of theos
module in this case.Searchable metadata
The text was updated successfully, but these errors were encountered: