haskell / haskell/cabal

During new-install regHooks doesn't know the temporary directory files are in.

Open
#5,889 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

The write protocol to the store is described in https://github.com/haskell/cabal/blob/7b8e6e5aa7d851d4caa132140673b17fe85970e3/cabal-install/Distribution/Client/Store.hs#L98-L115

```
-- * Register the package into the package db. Note that the files are not in
-- their final location at this stage so registration file checks may need
-- to be disabled.
--
-- * Atomically rename the temp dir to the final store entry location.
```

Thus `regHook` cannot post process stuff, as even it knows the final locations, it doesn't know current locations. The current location is needed if intent is to post-process files on the **TARGET** machine.
If they end up in the same temp directory, then they will be atomically moved as directory is renamed.

TL;DR registration hooks should know the **temporary** (to find files) and **final** (to burn-in right locations, if necessary) (data) directories.

Without changing the `Cabal` (i.e. for this to work with older `Cabal`s), we have to rely on some side-channel. I think setting an environment variable might be OK approach.

### happy

`happy` solves this problem by not using `regHook`:

- `postBuild`: generates new files
- `copyHook` and `instHook`s are amended with new files, so they are copied as well.
- This works, as `happy` post-processing isn't dependent on any artifact from the package

### Agda

`Agda` work around this problem by not erroring, only warning when postprocess fails
- this is ok in user installations, as files will be postprocessed when accessed
- global installation may result in inconsistent state, as datadir isn't writeable by ordinary users
- https://github.com/agda/agda/commit/f18591c94142b8191917c6900093242bba99408e#diff-8288955e209cfbead5b318a8598be9c0 breaks `new-install` (and also local `new-build`)
- It seems that `Agda` uses globbing now, and not explicit list of builtins, so I'd recommend them to revert to using only a warning

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.