Don't update ghcup if already latest version

Fixes #2
This commit is contained in:
Julian Ospald 2020-04-15 13:57:44 +02:00
parent ad4d185ead
commit f4242b10e7
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
4 changed files with 26 additions and 7 deletions

View File

@ -80,7 +80,7 @@ data Command
| Rm RmOptions | Rm RmOptions
| DInfo | DInfo
| Compile CompileCommand | Compile CompileCommand
| Upgrade UpgradeOpts | Upgrade UpgradeOpts Bool
| NumericVersion | NumericVersion
| ToolRequirements | ToolRequirements
@ -194,9 +194,12 @@ com =
) )
<> command <> command
"upgrade" "upgrade"
( Upgrade (info ((Upgrade <$> upgradeOptsP <*>
<$> (info (upgradeOptsP <**> helper) (progDesc "Upgrade ghcup")) switch
(short 'f' <> long "force" <> help
"Force update"
) )
) <**> helper) (progDesc "Upgrade ghcup"))
<> command <> command
"compile" "compile"
( Compile ( Compile
@ -626,6 +629,7 @@ main = do
, NoCompatiblePlatform , NoCompatiblePlatform
, NoCompatibleArch , NoCompatibleArch
, NoDownload , NoDownload
, NoUpdate
, FileDoesNotExistError , FileDoesNotExistError
, CopyError , CopyError
, DownloadFailed , DownloadFailed
@ -770,7 +774,7 @@ Check the logs at ~/.ghcup/logs and the build directory #{tmpdir} for more clues
VLeft e -> VLeft e ->
runLogger ($(logError) [i|#{e}|]) >> exitFailure runLogger ($(logError) [i|#{e}|]) >> exitFailure
Upgrade (uOpts) -> do Upgrade (uOpts) force -> do
target <- case uOpts of target <- case uOpts of
UpgradeInplace -> do UpgradeInplace -> do
efp <- liftIO $ getExecutablePath efp <- liftIO $ getExecutablePath
@ -783,7 +787,7 @@ Check the logs at ~/.ghcup/logs and the build directory #{tmpdir} for more clues
void void
$ (runUpgrade $ do $ (runUpgrade $ do
liftE $ upgradeGHCup dls target liftE $ upgradeGHCup dls target force
) )
>>= \case >>= \case
VRight v' -> do VRight v' -> do
@ -791,6 +795,9 @@ Check the logs at ~/.ghcup/logs and the build directory #{tmpdir} for more clues
runLogger runLogger
$ $(logInfo) $ $(logInfo)
[i|Successfully upgraded GHCup to version #{pretty_v}|] [i|Successfully upgraded GHCup to version #{pretty_v}|]
VLeft (V NoUpdate) ->
runLogger $ $(logWarn)
[i|No GHCup update available|]
VLeft e -> VLeft e ->
runLogger ($(logError) [i|#{e}|]) >> exitFailure runLogger ($(logError) [i|#{e}|]) >> exitFailure

View File

@ -675,6 +675,8 @@ upgradeGHCup :: ( MonadMask m
) )
=> GHCupDownloads => GHCupDownloads
-> Maybe (Path Abs) -- ^ full file destination to write ghcup into -> Maybe (Path Abs) -- ^ full file destination to write ghcup into
-> Bool -- ^ whether to force update regardless
-- of currently installed version
-> Excepts -> Excepts
'[ CopyError '[ CopyError
, DigestError , DigestError
@ -683,12 +685,14 @@ upgradeGHCup :: ( MonadMask m
, NoCompatibleArch , NoCompatibleArch
, NoCompatiblePlatform , NoCompatiblePlatform
, NoDownload , NoDownload
, NoUpdate
] ]
m m
Version Version
upgradeGHCup dls mtarget = do upgradeGHCup dls mtarget force = do
lift $ $(logInfo) [i|Upgrading GHCup...|] lift $ $(logInfo) [i|Upgrading GHCup...|]
let latestVer = fromJust $ getLatest dls GHCup let latestVer = fromJust $ getLatest dls GHCup
when (not force && (latestVer < pvpToVersion ghcUpVer)) $ throwE NoUpdate
pfreq <- liftE platformRequest pfreq <- liftE platformRequest
dli <- lE $ getDownloadInfo GHCup latestVer pfreq dls dli <- lE $ getDownloadInfo GHCup latestVer pfreq dls
tmp <- lift withGHCupTmpDir tmp <- lift withGHCupTmpDir

View File

@ -30,6 +30,10 @@ data NoCompatiblePlatform = NoCompatiblePlatform String -- the platform we got
data NoDownload = NoDownload data NoDownload = NoDownload
deriving Show deriving Show
-- | No update available or necessary.
data NoUpdate = NoUpdate
deriving Show
-- | The Architecture is unknown and unsupported. -- | The Architecture is unknown and unsupported.
data NoCompatibleArch = NoCompatibleArch String data NoCompatibleArch = NoCompatibleArch String
deriving Show deriving Show

View File

@ -240,3 +240,7 @@ addToCurrentEnv :: MonadIO m
addToCurrentEnv adds = do addToCurrentEnv adds = do
cEnv <- liftIO $ getEnvironment cEnv <- liftIO $ getEnvironment
pure (adds ++ cEnv) pure (adds ++ cEnv)
pvpToVersion :: PVP -> Version
pvpToVersion = either (\_ -> error "Couldn't convert PVP to Version") id . version . prettyPVP