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

Allow multiple state caches #4642

Merged
merged 2 commits into from
Apr 30, 2021
Merged

Allow multiple state caches #4642

merged 2 commits into from
Apr 30, 2021

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Apr 22, 2021

At present $OPAMROOT/repo/state.cache will be reset if the magic string does not match the version of opam-state / opam. This is tedious when developing and also visible to users as opam-state has a slightly different version from an opam binary.

The fix is quite simple: include the magic string in the filename as well, and tolerate having multiple cache files. state.cache is only ever written if something changed, and all that happens now is that $OPAMROOT/repo/*.cache is erased prior to writing the new cache (since other opam-state / opam binaries actually must regenerate the file).

As the cache files are all reset at opam update, even developers shouldn't see too many of them accumulating.

Fixes #4554. It can't directly be backported to 2.0.9, because 2.0.8 and earlier don't delete *.cache on a write. The "algorithm" could be adapted where opam 2.0.9 always erases its own cache of state.cache is newer, but I'm not convinced this is worth it. opam 2.1 does not require this kind of change, because even if opam 2.0.9 can read an opam root, it's never going to write to it, so the cache can't be invalidated.

Instead of writing state.cache, opam now writes state-magic.cache which
means that two opam binaries / libraries no longer keep regenerating the
state cache just because they can't read the one which was there before.

Just prior to _writing_ the state cache (e.g. after opam update or any
repo operation), all the .cache files in the directory are erased.

opam 2.0 is either unable to read a 2.1 root or will never write to it
(opam 2.0.9), so this change is backwards compatible.
@dra27 dra27 added this to PR in Progress in Opam 2.1.x via automation Apr 22, 2021
@dra27 dra27 added this to the 2.1.0~rc milestone Apr 22, 2021
@dra27
Copy link
Member Author

dra27 commented Apr 22, 2021

This is speculatively on the 2.1.0~rc milestone - we might remove it in the morning.

@dra27 dra27 moved this from PR in Progress to PR To review in Opam 2.1.x Apr 23, 2021
Opam 2.1.x automation moved this from PR To review to PR Finalised Apr 30, 2021
@dra27 dra27 merged commit a70ed4f into ocaml:master Apr 30, 2021
Opam 2.1.x automation moved this from PR Finalised to Done Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Opam 2.1.x
  
Done
Development

Successfully merging this pull request may close these issues.

opam-state 2.0.8 and opam 2.0.8 are competing to rebuild the repository cache
2 participants