Skip to content

Commit

Permalink
Replace symlinkable with symlink taking InstallExe
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Oct 19, 2023
1 parent 84337db commit c610d7f
Showing 1 changed file with 32 additions and 37 deletions.
69 changes: 32 additions & 37 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,34 @@ disableTestsBenchsByDefault configFlags =
, configBenchmarks = Flag False <> configBenchmarks configFlags
}

symlink :: OverwritePolicy -> InstallExe -> UnitId -> UnqualComponentName -> Symlink
symlink
overwritePolicy
InstallExe{installDir, mkSourceBinDir, mkExeName, mkFinalExeName}
unit
exe =
Symlink
overwritePolicy
installDir
(mkSourceBinDir unit)
(mkExeName exe)
(mkFinalExeName exe)

errorMessage :: Pretty a => OverwritePolicy -> InstallMethod -> FilePath -> a -> String
errorMessage overwritePolicy installMethod installdir exe = case overwritePolicy of
NeverOverwrite ->
"Path '"
<> (installdir </> prettyShow exe)
<> "' already exists. "
<> "Use --overwrite-policy=always to overwrite."
-- This shouldn't even be possible, but we keep it in case
-- symlinking/copying logic changes
_ ->
case installMethod of
InstallMethodSymlink -> "Symlinking"
InstallMethodCopy ->
"Copying" <> " '" <> prettyShow exe <> "' failed."

-- | Check if we can Symlink/copy every exe from a package from the store to a given location
installableUnitExes
:: Verbosity
Expand All @@ -1100,9 +1128,9 @@ installableUnitExes
installableUnitExes
verbosity
overwritePolicy
InstallExe{installMethod, installDir, mkSourceBinDir, mkExeName, mkFinalExeName}
installExe@InstallExe{installMethod, installDir}
(unit, components) = do
symlinkables :: [Bool] <- traverse (symlinkable overwritePolicy mkSourceBinDir mkExeName mkFinalExeName installDir unit) exes
symlinkables :: [Bool] <- traverse (symlinkableBinary . symlink overwritePolicy installExe unit) exes
traverse_ warnAbout (zip symlinkables exes)
where
exes = catMaybes $ (exeMaybe . fst) <$> components
Expand All @@ -1125,9 +1153,9 @@ installUnitExes
installUnitExes
verbosity
overwritePolicy
InstallExe{installMethod, installDir, mkSourceBinDir, mkExeName, mkFinalExeName}
installExe@InstallExe{installMethod, installDir, mkSourceBinDir, mkExeName, mkFinalExeName}
(unit, components) = do
symlinkables :: [Bool] <- traverse (symlinkable overwritePolicy mkSourceBinDir mkExeName mkFinalExeName installDir unit) exes
symlinkables :: [Bool] <- traverse (symlinkableBinary . symlink overwritePolicy installExe unit) exes
if and symlinkables
then traverse_ installAndWarn exes
else traverse_ warnAbout (zip symlinkables exes)
Expand All @@ -1151,39 +1179,6 @@ installUnitExes
installMethod
unless success $ die' verbosity (errorMessage overwritePolicy installMethod installDir exe)

symlinkable
:: OverwritePolicy
-> (UnitId -> FilePath)
-> (UnqualComponentName -> FilePath)
-> (UnqualComponentName -> FilePath)
-> FilePath
-> UnitId
-> UnqualComponentName
-> IO Bool
symlinkable overwritePolicy mkSourceBinDir mkExeName mkFinalExeName installdir unit exe =
symlinkableBinary
(Symlink
overwritePolicy
installdir
(mkSourceBinDir unit)
(mkExeName exe)
(mkFinalExeName exe))

errorMessage :: Pretty a => OverwritePolicy -> InstallMethod -> FilePath -> a -> String
errorMessage overwritePolicy installMethod installdir exe = case overwritePolicy of
NeverOverwrite ->
"Path '"
<> (installdir </> prettyShow exe)
<> "' already exists. "
<> "Use --overwrite-policy=always to overwrite."
-- This shouldn't even be possible, but we keep it in case
-- symlinking/copying logic changes
_ ->
case installMethod of
InstallMethodSymlink -> "Symlinking"
InstallMethodCopy ->
"Copying" <> " '" <> prettyShow exe <> "' failed."

-- | Install a specific exe.
installBuiltExe
:: Verbosity
Expand Down

0 comments on commit c610d7f

Please sign in to comment.