cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Add check on project root file and fail if broken link

Open albertodvp opened this issue 1 year ago • 2 comments

This PR modifies behaviour or interface**

Include the following checklist in your PR:

QA Notes

Build patched version

cabal build cabal-install
alias patchedCabal=$(cabal list-bin cabal-install)

Reproduce

Not patched version

cd "$(mktemp --directory)"
cabal init --exe --simple
ln -s I-do-not-exist cabal.project
cabal build

Expected behavour: cabal ignores the broken link and builds the project (ignoring the cabal.project and not signaling anything)

Patched version

Then, slighly adapting the example provided in the issue

cd "$(mktemp --directory)"
patchedCabal init --exe --simple
ln -s I-do-not-exist cabal.project
patchedCabal build

Expected behavour: cabal should exit with status code 1 and should print:

The given project file 'cabal.project' is broken. Is it a broken symbolic link?

Resolves #9937

albertodvp avatar Jun 11 '24 20:06 albertodvp

I don't think it's particularly valuable to add a changelog for this, but let me know if you think otherwise

albertodvp avatar Jun 13 '24 19:06 albertodvp

It's still a user-visible change, and entirely possible that someone relies on the old behavior (granting that that's relying on a bug, but https://xkcd.com/1172/).

geekosaur avatar Jun 13 '24 19:06 geekosaur

Confirmed working on Windows:

CMD> mklink cabal.project I-do-not-exist
symbolic link created for cabal.project <<===>> I-do-not-exist
➜ rm I-do-not-exist
➜ ls -lah cabal.project
lrwxrwxrwx 1 Javier Javier 4 Jul 22 23:53 cabal.project -> I-do-not-exist
➜ $CABAL build
Warning: this is a debug build of cabal-install with assertions enabled.
The given project file 'cabal.project' is broken. Is it a broken symbolic link?

jasagredo avatar Jul 22 '24 21:07 jasagredo

This is my first PR on Cabal, and I'm not sure how the process works (I couldn't find any information in the CONTRIBUTING file). Should I rebase it periodically? Am I missing anything to get this PR reviewed?

albertodvp avatar Jul 25 '24 14:07 albertodvp

Hey @albertodvp! I'm sorry you had to wait for so long. Don't worry about rebasing. We just need to get around to reviewing your PR: two approvals are necessary. I prodded people on Matrix, so, hopefully, this can be done this or next week. After two approvals we'll see how to proceed.

ulysses4ever avatar Jul 25 '24 15:07 ulysses4ever

Usually the attention: needs-review label is enough, but PRs sometimes get stuck there. My suggestion would be:

  • Rebase the feature on top of master.
  • Seems you were in the process of adding tests? or were you just fixing those cabal.project files (were they broken?)?
  • I would suggest adding a test in any case.
  • Hopefully someone will come and review the PR, otherwise you can ask in the Matrix channel.

jasagredo avatar Jul 25 '24 15:07 jasagredo

Thank you!

I did add some tests, I'm happy to add others if you have some requests :relaxed:

albertodvp avatar Jul 25 '24 15:07 albertodvp

Little things.

Strictly speaking, this is a race condition. It doesn't really matter in this case, though; you just gets suboptimal messaging.

Thank you for the review! Could you please help me see where I've introduced a race condition?

albertodvp avatar Jul 25 '24 15:07 albertodvp

It's the very concept: checking something before use instead of at the time of use; in this case, that would be reporting why opening the project file in one of the withProject… etc. functions failed. (Look up "TOCTOU" in a search engine.)

geekosaur avatar Jul 25 '24 16:07 geekosaur

The next step would be setting a merge label when the author is happy with the PR and there are no lingering discussions.

ulysses4ever avatar Jul 25 '24 16:07 ulysses4ever

"Pull request #10103 has been removed from the queue squash-merge: The pull request cannot be checked because of an incompatibility with branch protections.". Help?

(I thought this might be a problem with #10260 at first, but (a) we've had successful merges since then (b) Mergify's log says this also happened on 27 July which was well before #10260.)

geekosaur avatar Aug 26 '24 04:08 geekosaur

Hi @geekosaur - I've just rebased and force-pushed. I hope that was ok

albertodvp avatar Aug 26 '24 11:08 albertodvp

Yes, that's fine and probably what it needed. Mergify's been being a bit weird of late for some reason; it doesn't like something that's in master that it's failing to rebase on itself, but manual rebases seem to un-stick it.

geekosaur avatar Aug 26 '24 11:08 geekosaur