-
Notifications
You must be signed in to change notification settings - Fork 368
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
Conversation
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 -> |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
LGTM besides the comment above! |
opam switch create foo --empty
doesn't write anenvironment
file. At this point,opam config revert-env
will not return any updates.opam env
will regenerate file. This PR fixes bothopam switch create --empty
to write theenvironment
file and alsoopam config revert-env
to regenerate it if it's missing (so belt-and-braces approach). Finally, the environment is also not checked inopam 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).