-
-
Notifications
You must be signed in to change notification settings - Fork 325
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
finalize_entry
uses path and FD that may diverge, could use just FD
#1786
Comments
finalize_entry
makes seemingly unnecessary use of path and FD that may divergefinalize_entry
uses path and FD that may diverge, could use just FD
Thanks a lot for pointing this out!
I think this is done solely because I wasn't aware of a 'path-less' way of doing this, and agree that A proper reset is a topic I will work on as the next big feature, and resolving the existing issues will be done first. |
I have a fix for this issue almost ready. It uses By "almost ready," I mean that the fix is done and passes tests, and I am already working on the PR description. I expect to have that open in ten minutes or so. It is a fix only for this, not for any other issues. Or, rather, not for any I have opened as of now or have seen, or that I am otherwise certain of. (For a possible further issue my forthcoming PR may fix, see below.) I think it somewhat improves behavior in race conditions, for the general reasons about race conditions described in this issue. But my main motivations with it are to simplify things, make operations more consistent, and point the way toward some other possible future changes, for example, by making clear which uses of paths are really conceptually operating on paths. I'm not sure exactly what you have planned, but my guess is that this may be consistent with it. (I mean that I guess it will not get in the way of your plan, not that you should be at all reluctant to change or replace any of it at any point. For example, if you eventually eliminate changing permissions on existing files, then that would replace most of the changes. But I think the changes in my PR would either leave that as easy to do before, or make it easier.) One area that is important to consider--important enough that I'm mentioning it here and not only in my PR description--is that if we open a file through a symlink and then use Nonetheless, I think this is something that should be examined in review before my forthcoming PR (or anything changing this) is merged. Assuming I my belief that the More specifically, the reason I suspect an improvement in that area is that the current code (both before and after #1764) uses |
I've opened #1803 for this. |
Thanks for sharing!
Please feel free to make these fixes as you think they should be done, my plans for
This is correct, Git and
Yes, I think this would be another bug and/or oversight! |
Current behavior 😯
When finishing checking out a file, we do this:
gitoxide/gix-worktree-state/src/checkout/entry.rs
Lines 285 to 296 in 8df0db2
This has both the path and an open file object, the latter of which on a Unix-like system has an associated open file descriptor. The path is used to set permissions on the file when it is being made executable (and when this was not done eagerly when creating the file anew). But the
File
object is used to access metadata and update the index. The metadata it accesses does not include the permissions, so this does not inherently produce any inconsistencies (and the commented note is not likely related to permissions). But this combination is nonetheless unintuitive, especially if the file is moved or replaced:As noted in #1783 ("Expected behavior", 5(iii)), we should be able to set the permissions through the open file descriptor (from the
File
object) rather than using the path:Expected behavior 🤔
I am not sure what the expected behavior is, because I don't know if there is a specific reason for timestamp and size metadata to be read through the file descriptor that was presumably used for writing, while using the original path to set permissions instead of using
fchmod
.fchmod
(possibly through a higher-level library likerustix
) should be used. Unless there is a separate reason not to do that.This may also eventually no longer be relevant: Setting permissions might stop being needed at all if files that don't have the target permissions are replaced instead of having their permissions changed.
Git behavior
I'm not sure, in full. However, as noted in #1783 and #1784, Git replaces files during checkout (deleting/unlinking them and creating a new file of the same), rather than reusing them (keeping them but overwriting their contents), in more circumstances than gitoxide does. So I wouldn't expect the choice between
chmod
andfchmod
to arise as often in the Git checkout implementation.Steps to reproduce 🕹
For the aspect of this that is about it being unclear why one operation uses the open file and the other uses the path, see above links.
For the aspect that speculates that this could worsen some race conditions, I don't have steps to reproduce that. I don't know how much of a problem it is and, as noted above, it may be that the current code is correct except for being under-documented with respect to why this disparity is actually useful.
The text was updated successfully, but these errors were encountered: