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 environment file handling for empty switches #3899

Merged
merged 3 commits into from
Jul 3, 2019

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Jun 28, 2019

opam switch create foo --empty doesn't write an environment file. At this point, opam config revert-env will not return any updates. opam env will regenerate file. This PR fixes both opam switch create --empty to write the environment file and also opam config revert-env to regenerate it if it's missing (so belt-and-braces approach). Finally, the environment is also not checked in opam switch create --empty because of the same branch, and this is fixed (it hurts Windows, which actually updates the environment at this point; it doesn't hurt Unix if you have the shell hook installed).

opam switch create --empty didn't write the switch environment file,
since this was only done if there were packages to install.
opam switch create --empty wouldn't display the out-of-date environment
warning, since no packages had been installed.
opam env will regenerate a missing environment file. This is extended to
opam config revert-env which would silently fail to do anything if the
environment file wasn't present.
let ensure_env_aux ?(set_opamroot=false) ?(set_opamswitch=false) ?(force_path=true) gt switch =
let env_file = OpamPath.Switch.environment gt.root switch in
if not (OpamFile.exists env_file) then
Some (OpamSwitchState.with_ `Lock_none gt @@ fun st ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good reason to not take the write lock directly in this case ? Lock upgrades should be avoided unless absolutely necessary (and the scenarios for deadlocks have been considered)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to change this, but this is a refactoring - it's exactly the code deleted below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right! I should ask @rjbou then :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env file is only regenerated & written if a write lock can be taken (not --safe, cf. 3691). We don't want to block opam env because of the missing environment file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, was I was suggesting is stg along the lines of:

  if not safe_mode && not OpamFile.exists env_file then OpamSwitchState.with_ `Lock_write gt @@ ... (* regenerate *)
  else OpamSwitchState.with_ `Lock_none gt @@ ...

the point would just be to avoid the use of OpamSwitchState.with_write_lock really, since we could detect the need beforehand and load with a write lock directly, which is always better & safer than upgrading existing locks.

@AltGr
Copy link
Member

AltGr commented Jul 1, 2019

LGTM besides the comment above!

@AltGr AltGr merged commit 24a1610 into ocaml:master Jul 3, 2019
@rjbou rjbou added this to the 2.1.0 milestone Jul 5, 2019
@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

3 participants