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

Prompt overwrite policy #5672

Merged
merged 3 commits into from
Nov 30, 2021
Merged

Conversation

fredefox
Copy link
Contributor

@fredefox fredefox commented Nov 8, 2018

When linking binaries into a globally accessible location on the machine --overwrite-policy=always is needed if an existing file sits where we are trying to create a link. This allows for a prompt-the-user strategy.


Please include the following checklist in your PR:

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
  • The documentation has been updated, if necessary.
    NA: Couldn't find any existing documentation about overwrite-policy.
  • If the change is docs-only, [ci skip] is used to avoid triggering the build bots.

How I tested the change:

I simply ran cabal new-install on cabal-install (after having installed cabal-install with my feature.

WIP

  • Testing on Windows. Help wanted
  • A way to globally configure --overwrite-policy=prompt as the default. This was my idea with the patch. I need a bit of help on how to achieve this though as I'm not familiar with the code-base.

haskell-pushbot pushed a commit to haskell-pushbot/cabal-binaries that referenced this pull request Nov 8, 2018
"url":"pull/5672",
"account":"haskell",
"repo":"cabal",
"commit": "f459bb10c1e75c425bdb8acdce892d00a231aed5",
"tag":"linux-7.10.3"
}
haskell-pushbot pushed a commit to haskell-pushbot/cabal-binaries that referenced this pull request Nov 8, 2018
"url":"pull/5672",
"account":"haskell",
"repo":"cabal",
"commit": "f459bb10c1e75c425bdb8acdce892d00a231aed5",
"tag":"linux-8.0.2"
}
@fgaz
Copy link
Member

fgaz commented Nov 8, 2018

A way to globally configure --overwrite-policy=prompt as the default. This was my idea with the patch. I need a bit of help on how to achieve this though as I'm not familiar with the code-base.

See #5644. SavedConfig represents the ~/.cabal/config file, but right now NewInstallFlags isn't in there

haskell-pushbot pushed a commit to haskell-pushbot/cabal-binaries that referenced this pull request Nov 8, 2018
"url":"pull/5672",
"account":"haskell",
"repo":"cabal",
"commit": "f459bb10c1e75c425bdb8acdce892d00a231aed5",
"tag":"linux-8.2.2"
}
haskell-pushbot pushed a commit to haskell-pushbot/cabal-binaries that referenced this pull request Nov 8, 2018
"url":"pull/5672",
"account":"haskell",
"repo":"cabal",
"commit": "f459bb10c1e75c425bdb8acdce892d00a231aed5",
"tag":"linux-8.4.3"
}
haskell-pushbot pushed a commit to haskell-pushbot/cabal-binaries that referenced this pull request Nov 8, 2018
"url":"pull/5672",
"account":"haskell",
"repo":"cabal",
"commit": "f459bb10c1e75c425bdb8acdce892d00a231aed5",
"tag":"linux-8.4.3-fdebug-expensive-assertions"
}
haskell-pushbot pushed a commit to haskell-pushbot/cabal-binaries that referenced this pull request Nov 8, 2018
"url":"pull/5672",
"account":"haskell",
"repo":"cabal",
"commit": "f459bb10c1e75c425bdb8acdce892d00a231aed5",
"tag":"osx-8.0.2"
}
haskell-pushbot pushed a commit to haskell-pushbot/cabal-binaries that referenced this pull request Nov 8, 2018
"url":"pull/5672",
"account":"haskell",
"repo":"cabal",
"commit": "f459bb10c1e75c425bdb8acdce892d00a231aed5",
"tag":"osx-7.10.3"
}
@23Skidoo
Copy link
Member

23Skidoo commented Nov 9, 2018

/cc @hvr

@hvr
Copy link
Member

hvr commented Nov 10, 2018

@23Skidoo I haven't yet looked at this in detail, but this is exactly the kind of overwrite policies I had in mind :-)

What I'm a bit unsure about though is how we can model interactivity into a future abstracted UI I/O layer (that thing for which the big "Cabal Monad" refactoring represents a pre-req) ... (but this isn't a blocker for this PR -- just something this reminds me of)

@fredefox fredefox changed the base branch from 2.4 to master February 3, 2019 14:45
@fredefox
Copy link
Contributor Author

fredefox commented Feb 3, 2019

I've changed the PR to target master. I just cherry-picked the one commit I have made towards this.

@fgaz
Copy link
Member

fgaz commented Mar 26, 2019

I added the new-install flags to SavedConfig with #5870 (not working yet due to a bug in how flags are handled: #5942)

There's a conflict now though

@gbaz
Copy link
Collaborator

gbaz commented Aug 12, 2021

I hope this can be picked up and worked on, seems like it is a nice ux improvement that everyone is on board with.

@gbaz
Copy link
Collaborator

gbaz commented Aug 16, 2021

@fgaz can you try to resolve the conflict here? This looks like something we should make happen...

@fgaz fgaz force-pushed the wip/prompt-overwrite-policy branch from e61b60d to f3f89d5 Compare August 20, 2021 11:31
@fgaz
Copy link
Member

fgaz commented Aug 20, 2021

I resolved the conflict, but the copy+prompt case is not handled. I left a TODO, if someone wants to finish this.

@fgaz
Copy link
Member

fgaz commented Aug 20, 2021

Also sorry for force-pushing @fredefox, I remembered too late that this wasn't my branch (github kept the old ref archived though)

@Mikolaj
Copy link
Member

Mikolaj commented Aug 25, 2021

@fredefox: thank you for your work so far. Would you like to add the missing case or are you busy ATM?

@Mikolaj
Copy link
Member

Mikolaj commented Sep 11, 2021

Given that @fredefox seems busy, I'm opening this PR to a rescue operation by any noble volunteers. Please feel free to overwrite this branch (or create a new PR if you insist).

@fredefox
Copy link
Contributor Author

Sorry @Mikolaj. Forgot to reply. My GitHub inbox is super swamped. I don't know if I'll look at this any time soon. Anyone should indeed feel free to take this over.

@fredefox
Copy link
Contributor Author

I've updated the PR. I seem to have some laziness/buffering-issue. The prompt is not displayed before hitting enter after which a parse-error is also printed. I might return to it later. Other people are still invited to contribute patches on top of this.

I was unsure what heading to put my change under in the change log.

@Mikolaj
Copy link
Member

Mikolaj commented Oct 25, 2021

Hi @fredefox! Thank you for you contribution. Please kindly format the changelog as, e.g., in #7766.

@Mikolaj
Copy link
Member

Mikolaj commented Nov 8, 2021

@fredefox: hi! may I help to get this PR merged before it rots? :)

@fredefox
Copy link
Contributor Author

fredefox commented Nov 9, 2021

Hi @Mikolaj. Feel free to take over. There is a remaining issue with my work. The prompt is not displayed eagerly enough. I'm not sure why. I suggest testing this, as I did, by running cabal-install Cabal twice. Once to install my change, and then once to see the prompt appear. I may return to this, but I make no promises as to when.

@Mikolaj
Copy link
Member

Mikolaj commented Nov 9, 2021

@fredefox: got it. No pressure. Thanks for sharing the problem --- perhaps somebody takes a look and gets a hunch as to why this happens, before you return.

@fredefox fredefox force-pushed the wip/prompt-overwrite-policy branch 2 times, most recently from b06b9e5 to 9882a8d Compare November 15, 2021 16:57
@fredefox
Copy link
Contributor Author

Hi @Mikolaj. I found the issue and I wrote a solution to it. Emphases on "a". Perhaps someone might have a better proposal than what I did. I figured out that in promptDefault the call to putStr did not write to stdout before the call to getLine triggered. I'm actually surprised by this, because if I compare it to, say, this program:

main :: IO ()
main = putStr "Hello" *> getLine *> pure ()

The output does indeed appear before blocking for input. Perhaps some strange interaction from the Interactive instance for IO? I don't really know.

Anyways. In summation, the PR is ready to go as-is as far as I can see.

Copy link
Member

@Mikolaj Mikolaj left a comment

Choose a reason for hiding this comment

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

I don't have an explanation, but I'm not surprised at all. I routinely flush whenever I finish adding to the displayed text.

@Mikolaj
Copy link
Member

Mikolaj commented Nov 15, 2021

@Mergifyio rebase

@mergify
Copy link
Contributor

mergify bot commented Nov 15, 2021

rebase

✅ Branch has been successfully rebased

Copy link
Member

@Kleidukos Kleidukos left a comment

Choose a reason for hiding this comment

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

Couple of changes, but it looks good overall. :)

cabal-install/src/Distribution/Client/InstallSymlink.hs Outdated Show resolved Hide resolved
Comment on lines 833 to 840
overwrite :: IO Bool
overwrite = remove >> copy
maybeOverwrite :: IO Bool
maybeOverwrite = do
a <- promptYesNo
"Existing file found while installing executable. Do you want to unlink that file? (y/n)"
MandatoryPrompt
if a then overwrite else pure a
Copy link
Member

Choose a reason for hiding this comment

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

You're doing this work twice, here and in InstallSymlink.hs. Could this maybe be unified? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it definitely might be able to do some refacturing to increase sharing between installBuiltExe and symlinkBinary. I'm not sure it's warranted in the case of maybeOverwrite. I'm personally not convinced that the code is made more legible by just doing it for maybeOverwrite, but I've included it in the latest commit (9f594be) for you to be the judge :)

@fredefox fredefox force-pushed the wip/prompt-overwrite-policy branch 2 times, most recently from 9f594be to b778903 Compare November 22, 2021 20:42
@Mikolaj
Copy link
Member

Mikolaj commented Nov 27, 2021

Is everybody happy with how the feedback was addressed? If so, I'm going to merge (and if nobody answers, I'm merging on Tuesday).

@Mikolaj
Copy link
Member

Mikolaj commented Nov 30, 2021

@Mergifyio rebase

@mergify
Copy link
Contributor

mergify bot commented Nov 30, 2021

rebase

✅ Branch has been successfully rebased

@Mikolaj
Copy link
Member

Mikolaj commented Nov 30, 2021

CI is OK. Merging. Thank you everybody!

@Mikolaj Mikolaj merged commit 5ef4d23 into haskell:master Nov 30, 2021
@fredefox
Copy link
Contributor Author

fredefox commented Dec 1, 2021

Thank you @Mikolaj!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants