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

bug: opam fails to handle corrupted packages #6365

Open
Banyc opened this issue Jan 15, 2025 · 4 comments
Open

bug: opam fails to handle corrupted packages #6365

Banyc opened this issue Jan 15, 2025 · 4 comments

Comments

@Banyc
Copy link

Banyc commented Jan 15, 2025

If your issue concerns a package not building, please report to
https://github.com/ocaml/opam-repository/issues or to the package maintainer
unless you are confident it is an issue in the opam tool itself.
If your issue concerns failures with the opam.ocaml.org website, please report to
https://github.com/ocaml/infrastructure/issues

❯ opam config report
# opam config report
# opam-version         2.3.0
# self-upgrade         no
# system               arch=arm64 os=macos os-distribution=homebrew os-version=14.5
# solver               builtin-mccs+glpk
# install-criteria     -removed,-count[avoid-version,changed],-count[version-lag,request],-count[version-lag,changed],-count[missing-depexts,changed],-changed
# upgrade-criteria     -removed,-count[avoid-version,changed],-count[version-lag,solution],-count[missing-depexts,changed],-new
# jobs                 11
# read-state           In /private/var/folders/rs/s_91mgrx38n9tg742t37h_t00000gn/T/opam-31163-a0be32/default/packages/octez-alcotezt/octez-alcotezt.17.1/opam:
unsupported or missing file format version; should be 2.0 or older

The file mentioned is a empty file.

This file bugs almost all the opam commands, following are examples:

❯ opam clean
Fatal error:
In /private/var/folders/rs/s_91mgrx38n9tg742t37h_t00000gn/T/opam-31104-37d38c/default/packages/octez-alcotezt/octez-alcotezt.17.1/opam:
unsupported or missing file format version; should be 2.0 or older
❯ opam update
Fatal error:
In /private/var/folders/rs/s_91mgrx38n9tg742t37h_t00000gn/T/opam-31191-16e3ad/default/packages/octez-alcotezt/octez-alcotezt.17.1/opam:
unsupported or missing file format version; should be 2.0 or older

And there is no way to uninstall the opam and reinstall it again since this binary was installed from script and not from any package manager like brew.

@Banyc
Copy link
Author

Banyc commented Jan 15, 2025

feature request: provide an option to uninstall the opam on the machine in bash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)" from the site

@rjbou
Copy link
Collaborator

rjbou commented Jan 16, 2025

There was a corruption during the update of repository, it is an internal error. Do you remember what is the command or the context just before that error?

To fix this internal error, you can remove the directory /private/var/folders/rs/s_91mgrx38n9tg742t37h_t00000gn/T/opam-31163-a0be32/default and then launch an opam update default to reload the repository.

We should add an option to opam repository remove to be able to delete a repository even if it contains error, something like --force.

And there is no way to uninstall the opam and reinstall it again since this binary was installed from script and not from any package manager like brew.

If you want to uninstall opam, you just need to remove the binary and the opam root. If you didn't set specific paths, binary should be in /usr/local/bin/opam and the opam root in $HOME/.opam.

@Banyc
Copy link
Author

Banyc commented Jan 16, 2025

@rjbou It could be a false statement bc it's been awhile: I did opam upgrade and ctrl+c it because it said I hadn't been update it for a long time and then so I could do opam update first.

The first fix doesn't work:

❯ rm -r /private/var/folders/rs/s_91mgrx38n9tg742t37h_t00000gn/T/opam-31163-a0be32/default

❯ opam update default
Fatal error:
In /private/var/folders/rs/s_91mgrx38n9tg742t37h_t00000gn/T/opam-45010-9a9301/default/packages/octez-alcotezt/octez-alcotezt.17.1/opam:
unsupported or missing file format version; should be 2.0 or older

The delete-and-install route works.

Thanks for the instructions!

@kit-ty-kate
Copy link
Member

I've managed to reproduce very simply by emptying one of the opam file in repo/default/packages/... and removing the repo cache file.

We should add an option to opam repository remove to be able to delete a repository even if it contains error, something like --force.

I'm not sure opam repository remove is the right place to respond to corrupted files. I feel like it would be more logical for opam update to not take into account the previous state of the repository.
In both cases anyway, sadly, from the point of view of our code it seems that to fix this issue we need to delay the loading of the repo cache file from the repository state and only use it if needed which is quite a large change

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

No branches or pull requests

3 participants