Skip to content

cabal new-install silently fails if symlink target already exists #5491

Closed
@hvr

Description

@hvr

Currently, when you e.g. cabal new-install hsc2hs --symlink-bindir=/tmp/bin, and something exists already in /tmp/bin, new-install will claim to

Symlinking hsc2hs

even though it failed to update the symlink.

E.g.

$ cabal new-install hsc2hs-0.68.3 --symlink-bindir=/tmp/bin/
Resolving dependencies...
Up to date
Symlinking hsc2hs

$ ls -l /tmp/bin/
total 0
lrwxrwxrwx 1 hvr hvr 127 Aug  2 11:17 hsc2hs -> ../../home/hvr/.cabal/store/ghc-8.2.2/hsc2hs-0.68.3-098a68e230c98f65b69ba9c636ab16a4395deacc40aff03647d85d54a5ad7aeb/bin/hsc2hs

that's ok so far, as the end-result was in fact having a symlink pointing to hsc2hs-0.68.3; however, when I request to new-install again which is expected to results in a different symlink, new-install silently fails to:

$ cabal new-install hsc2hs-0.68.2 --symlink-bindir=/tmp/bin/
Resolving dependencies...
Build profile: -w ghc-8.2.2 -O1
In order, the following will be built (use -v for more details):
 - hsc2hs-0.68.2 (exe:hsc2hs) (requires download & build)
Downloading  hsc2hs-0.68.2
Downloaded   hsc2hs-0.68.2
Starting     hsc2hs-0.68.2 (exe:hsc2hs)
Building     hsc2hs-0.68.2 (exe:hsc2hs)
Installing   hsc2hs-0.68.2 (exe:hsc2hs)
Completed    hsc2hs-0.68.2 (exe:hsc2hs)
Symlinking hsc2hs

$ ls -l /tmp/bin/
total 0
lrwxrwxrwx 1 hvr hvr 127 Aug  2 11:17 hsc2hs -> ../../home/hvr/.cabal/store/ghc-8.2.2/hsc2hs-0.68.3-098a68e230c98f65b69ba9c636ab16a4395deacc40aff03647d85d54a5ad7aeb/bin/hsc2hs

Consequently, new-install ought to at very least warn if not even error (or even better yet overwrite), when it cannot produce the desired final state of the symlink; specifically,

I'd expect two subsequent invocations of e.g.

$ cabal new-install hsc2hs-0.68.3 --symlink-bindir=/tmp/bin/
$ cabal new-install hsc2hs-0.68.3 --symlink-bindir=/tmp/bin/

to be idempotent and the 2nd invocation not warn if the first one succeded, as the resulting end-state of the symlink would be unchanged.


As to whether we ought to

  • warn (and don't overwrite existing entries)
  • error (i.e. abort; don't do anything)
  • force to overwrite (in which case I'd expect a warning/info message if an existing symlink was updated to a new target)

I'm not totally sure (I'd prefer the overwrite variant); I merely claim that the current situation is definitely bad/wrong, and any of the options above would be an improvement.

See also #5408 where old-build appears to have a warning

Warning: could not create a symlink in /home/me/.cabal/bin for hlint because the file exists there already but is not managed by cabal. You can create a symlink for this executable manually if you wish. The executable file has been installed at /home/me/.cabal/bin/hlint

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions