Skip to content
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

Fix file locking on Windows #3347

Merged
merged 3 commits into from
May 15, 2018
Merged

Fix file locking on Windows #3347

merged 3 commits into from
May 15, 2018

Conversation

dra27
Copy link
Member

@dra27 dra27 commented May 10, 2018

Another bit from #3260.

These three commits are worth looking at individually.

  • Close all lock files on error: this, as you noted in Fully test native Windows in the testsuite #3260, this shouldn't be necessary, but given that any coding error could result in this, I'd prefer to keep it. It could possibly be extended to display warnings if OpamSystem.release_all_locks actually has to release any locks? It would seem to be much better to have warnings displayed, which need fixing, than to get error messages about being unable to remove a directory (in this case ~/.opam), as failing to delete the directory in this instance will probably result in worse error messages for the user on the next command they run.
  • Fix file locking on Windows: this is sound, though could potentially result in the loss of the lock to another opam process. This could be fixed by converting locks to be pairs of read and write locks if you want? A benefit of doing that is the code would cease to be Windows-specific (it would just retain a comment for why it can't be done the more obvious way).
  • Fix reading/writing of OpamRepositoryState cache: is a simple refactoring to prevent opening a file twice, since this doesn't work on Windows if it's locked for writing (even by the same process).

dra27 added 3 commits May 10, 2018 14:56
Windows cannot erase directories if there are open file handles. Limited
mechanism added for tracking lock handles to allow the .opam directory
to be deleted if an error occurs during opam init.

Signed-off-by: David Allsopp <david.allsopp@metastack.com>
The underlying function for flock on Windows doesn't support promotion
of read locks or demotion of write locks and the locks are also not
recursive.

Signed-off-by: David Allsopp <david.allsopp@metastack.com>
On Windows, locked files should not be opened twice even within the same
process, so utilise the adapted OpamFilename.with_flock functions to
prevent the need for a second fd.

Signed-off-by: David Allsopp <david.allsopp@metastack.com>
@AltGr
Copy link
Member

AltGr commented May 15, 2018

Seems fine, thanks!

@AltGr AltGr merged commit 8a0957a into ocaml:master May 15, 2018
@dra27 dra27 deleted the windows-locking branch June 10, 2018 12:21
@dra27 dra27 mentioned this pull request Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants