cabal-install-3.12.1.0: The command-line interface for Cabal and Hackage.

Copyright | (c) Duncan Coutts 2008
License | BSD-like
Maintainer | cabal-devel@haskell.org
Stability | provisional
Portability | portable
Safe Haskell | None
Language | Haskell2010

Distribution.Client.InstallSymlink

Description

Managing installing binaries with symlinks.

Synopsis

- data Symlink = Symlink {
  - overwritePolicy :: OverwritePolicy
  - publicBindir :: FilePath
  - privateBindir :: FilePath
  - publicName :: FilePath
  - privateName :: String
  }
- symlinkBinaries :: Platform -> Compiler -> OverwritePolicy -> ConfigFlags -> InstallFlags -> InstallPlan -> BuildOutcomes -> IO [(PackageIdentifier, UnqualComponentName, FilePath)]
- symlinkBinary :: Symlink -> IO Bool
- symlinkableBinary :: Symlink -> IO Bool
- trySymlink :: Verbosity -> IO Bool
- promptRun :: String -> IO Bool -> IO Bool

# Documentation

data Symlink #

A record needed to either check if a symlink is possible or to create a symlink. Also used if copying instead of symlinking.

Constructors

Symlink |
Fields overwritePolicy :: OverwritePolicy Whether to force overwrite an existing file. publicBindir :: FilePath The canonical path of the public bin dir eg `homeuser/bin`. privateBindir :: FilePath The canonical path of the private bin dir eg `homeuser.cabalbin`. publicName :: FilePath The name of the executable to go in the public bin dir, eg `foo`. privateName :: String The name of the executable to in the private bin dir, eg `foo-1.0`.

symlinkBinaries :: Platform -> Compiler -> OverwritePolicy -> ConfigFlags -> InstallFlags -> InstallPlan -> BuildOutcomes -> IO [(PackageIdentifier, UnqualComponentName, FilePath)] #

We would like by default to install binaries into some location that is on the user's PATH. For per-user installations on Unix systems that basically means the `~bin` directory. On the majority of platforms the `~bin` directory will be on the user's PATH. However some people are a bit nervous about letting a package manager install programs into `~bin`.

A compromise solution is that instead of installing binaries directly into `~bin`, we could install them in a private location under `~.cabalbin` and then create symlinks in `~bin`. We can be careful when setting up the symlinks that we do not overwrite any binary that the user installed. We can check if it was a symlink we made because it would point to the private dir where we install our binaries. This means we can install normally without worrying and in a later phase set up symlinks, and if that fails then we report it to the user, but even in this case the package is still in an OK installed state.

This is an optional feature that users can choose to use or not. It is controlled from the config file. Of course it only works on POSIX systems with symlinks so is not available to Windows users.

symlinkBinary :: Symlink -> IO Bool #

Symlink binary.

The paths are take in pieces, so we can make relative link when possible. `True` if creating the symlink was successful. `False` if there was another file there already that we did not own. Other errors like permission errors just propagate as exceptions.

symlinkableBinary :: Symlink -> IO Bool #

Can we symlink a binary?

`True` if creating the symlink would be succeed, being optimistic that the user will agree if prompted to overwrite.

trySymlink :: Verbosity -> IO Bool #

Try to make a symlink in a temporary directory.

If this works, we can try to symlink: even on Windows.

promptRun :: String -> IO Bool -> IO Bool #