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 post-install-commands hooks to modify/remove installed files #4388

Conversation

lefessan
Copy link
Contributor

This modification is necessary because opam-bin uses the post-install-commands to share files between switches using hard links. Unfortunately, without this PR, such actions modify the digests of the files just after their recording, so that opam remove will complain that the installed files have been modified.

Please update master_changes.md file with your changes.

@AltGr
Copy link
Member

AltGr commented Oct 12, 2020

LGTM, thanks!

@hannesm
Copy link
Member

hannesm commented Oct 12, 2020

I'm a bit sceptical this is a good idea - is there an overview which phases and hooks are allowed to do what? At least, the documentation should be adjusted:

The post-install-commands hook also has access to an extra variable installed-files which expands to the list of files and directories added or modified during the installation of the package. Note that this hook is run after the scan for installed files is done, so any additional installed files won't be recorded and must be taken care of by a pre-remove-commands hook.

wouldn't such a post-install and a corresponding pre-remove work for opam-bin?

@lefessan
Copy link
Contributor Author

wouldn't such a post-install and a corresponding pre-remove work for opam-bin?

opam-bin already adds files during the post-install hook that it later removes using the pre-remove hook.
But in this particular case, it is not about adding new files, but changing files that have just been installed. Even if opam-bin records its changes, it won't be able to restore the original files, so opam will keep complaining that the files that were installed were either removed or modified. Keeping a copy of the file would defeat the purpose which is to save space on the disk by sharing installed files between switches.

Note that this PR does not allow a post-install hook to add new files in the changes, only to modify/remove some of them.

@avsm
Copy link
Member

avsm commented Oct 12, 2020

Lets not be hasty about adding in hook features this late in opam 2.1's release cycle without careful justification, please. I think it's important to understand the power of these hooks:

  • does this hook facility bypass the sandboxing process?
  • can a post-install hook modify files installed by other packages, or just those under its original control?

@lefessan
Copy link
Contributor Author

Lets not be hasty about adding in hook features this late in opam 2.1's release cycle without careful justification, please. I think it's important to understand the power of these hooks:

  • does this hook facility bypass the sandboxing process?
  • can a post-install hook modify files installed by other packages, or just those under its original control?

Hooks completely bypass the sandboxing process : it is already possible for post-install hooks (and other hooks) to modify files anywhere on the system.

@AltGr
Copy link
Member

AltGr commented Oct 12, 2020

Just clarifying two points:

  • sandboxing is itself a hook, so command-wrapping hooks can be put inside or outside the sandbox by customising the order of definition in ~/.opam/config; pre/post hooks are not sandboxed.
  • this PR really doesn't allow hooks to do anything they couldn't: it just actually handles the case where the post-install hook modifies files in a more consistent way.

The latter explains I have no objection, since the PR does not change existing features but improves handling for a specific case of an existing feature.

EDIT: but yes the PR title is pretty misleading :)

master_changes.md Outdated Show resolved Hide resolved
@rjbou rjbou added this to PR in Progress in Opam 2.1.x via automation Oct 12, 2020
@rjbou rjbou added this to the 2.1.0~beta3 milestone Oct 12, 2020
@hannesm
Copy link
Member

hannesm commented Oct 12, 2020

thanks for the explanation @AltGr.

@avsm
Copy link
Member

avsm commented Oct 12, 2020

Thanks for the explanations. Could we get the Changes entry to be more accurate then? Specifically, it appears that opam 2.1 is now tracking the results of ~/.opam changes made during the post-install hook execution and registering those with opam. Are there any other implications of making this change (e.g. to opam list --show-files?)

@lefessan
Copy link
Contributor Author

Thanks for the explanations. Could we get the Changes entry to be more accurate then? Specifically, it appears that opam 2.1 is now tracking the results of ~/.opam changes made during the post-install hook execution and registering those with opam. Are there any other implications of making this change (e.g. to opam list --show-files?)

There is already an entry in the Changes that is added with the PR. Note that only the files that were installed by the package are checked for modification, other files added/modified by the post-install hook are not, and should be removed/restored by the plugin using the pre-remove hook.

@lefessan
Copy link
Contributor Author

Are there any other implications of making this change (e.g. to opam list --show-files?)

Users that do not use opam-bin usually have no post-install hook, so nothing is changed for them (no additional cost). For those using a post-install hook, the PR does not increase the power of what the hook can do, it just prevents them from corrupting opam changes files.

@rjbou rjbou moved this from PR in Progress to PR Finalised in Opam 2.1.x Oct 16, 2020
@AltGr
Copy link
Member

AltGr commented Oct 16, 2020

Just one last tidbit, the last sentence in the manual here should be updated to reflect the change. The doc doesn't become incorrect, but just precise something along the lines of "Modified installed files will be handled correctly by opam"

Source: https://github.com/ocaml/opam/blob/master/doc/pages/Manual.md

@lefessan lefessan force-pushed the z-2020-10-11-allow-file-modifications-in-post-install branch from 978191e to 0f5706b Compare October 16, 2020 12:39
@lefessan
Copy link
Contributor Author

Just one last tidbit, the last sentence in the manual here should be updated to reflect the change. The doc doesn't become incorrect, but just precise something along the lines of "Modified installed files will be handled correctly by opam"

Source: https://github.com/ocaml/opam/blob/master/doc/pages/Manual.md

Indeed, I have modified the Manual file in this new version.

master_changes.md Outdated Show resolved Hide resolved
Co-authored-by: R. Boujbel <rjbou@ocamlpro.com>
Copy link
Collaborator

@rjbou rjbou left a comment

Choose a reason for hiding this comment

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

Small changes, but LGTM!
In order to keep consistency with function inf OpamDirTrack, update should take a dirname and not a string.

src/core/opamDirTrack.mli Outdated Show resolved Hide resolved
src/client/opamAction.ml Outdated Show resolved Hide resolved
src/core/opamDirTrack.ml Show resolved Hide resolved
lefessan and others added 3 commits October 20, 2020 15:30
Co-authored-by: R. Boujbel <rjbou@ocamlpro.com>
Co-authored-by: R. Boujbel <rjbou@ocamlpro.com>
Co-authored-by: R. Boujbel <rjbou@ocamlpro.com>
@rjbou rjbou merged commit 73ca1da into ocaml:master Oct 21, 2020
Opam 2.1.x automation moved this from PR Finalised to Done Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Opam 2.1.x
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants