Fix cabalSet
for pre-release versions
This commit is contained in:
parent
af811f3dbc
commit
86b0e4b31b
@ -259,18 +259,33 @@ cabalInstalled ver = do
|
|||||||
cabalSet :: (MonadIO m, MonadThrow m) => m (Maybe Version)
|
cabalSet :: (MonadIO m, MonadThrow m) => m (Maybe Version)
|
||||||
cabalSet = do
|
cabalSet = do
|
||||||
cabalbin <- (</> [rel|cabal|]) <$> liftIO ghcupBinDir
|
cabalbin <- (</> [rel|cabal|]) <$> liftIO ghcupBinDir
|
||||||
|
b <- fmap (== SymbolicLink) $ liftIO $ getFileType cabalbin
|
||||||
|
if
|
||||||
|
| b -> do
|
||||||
|
liftIO $ handleIO' NoSuchThing (\_ -> pure $ Nothing) $ do
|
||||||
|
link <- readSymbolicLink $ toFilePath cabalbin
|
||||||
|
Just <$> linkVersion link
|
||||||
|
| otherwise -> do -- legacy behavior
|
||||||
mc <- liftIO $ handleIO (\_ -> pure Nothing) $ fmap Just $ executeOut
|
mc <- liftIO $ handleIO (\_ -> pure Nothing) $ fmap Just $ executeOut
|
||||||
cabalbin
|
cabalbin
|
||||||
["--numeric-version"]
|
["--numeric-version"]
|
||||||
Nothing
|
Nothing
|
||||||
fmap join $ forM mc $ \c -> if
|
fmap join $ forM mc $ \c -> if
|
||||||
| not (B.null (_stdOut c))
|
| not (B.null (_stdOut c)), _exitCode c == ExitSuccess -> do
|
||||||
, _exitCode c == ExitSuccess -> do
|
|
||||||
let reportedVer = fst . B.spanEnd (== _lf) . _stdOut $ c
|
let reportedVer = fst . B.spanEnd (== _lf) . _stdOut $ c
|
||||||
case version $ decUTF8Safe reportedVer of
|
case version $ decUTF8Safe reportedVer of
|
||||||
Left e -> throwM e
|
Left e -> throwM e
|
||||||
Right r -> pure $ Just r
|
Right r -> pure $ Just r
|
||||||
| otherwise -> pure Nothing
|
| otherwise -> pure Nothing
|
||||||
|
where
|
||||||
|
linkVersion :: MonadThrow m => ByteString -> m Version
|
||||||
|
linkVersion bs = do
|
||||||
|
t <- throwEither $ E.decodeUtf8' bs
|
||||||
|
throwEither $ MP.parse parser "" t
|
||||||
|
where
|
||||||
|
parser =
|
||||||
|
MP.chunk "cabal-" *> version'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user