Compare commits
1 Commits
fix-instal
...
merge-requ
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cfff674b7 |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -116,20 +116,7 @@ else
|
|||||||
if [ "${OS}" = "LINUX" ] ; then
|
if [ "${OS}" = "LINUX" ] ; then
|
||||||
eghcup --downloader=wget prefetch ghc 8.10.3
|
eghcup --downloader=wget prefetch ghc 8.10.3
|
||||||
eghcup --offline install ghc 8.10.3
|
eghcup --offline install ghc 8.10.3
|
||||||
if [ "${ARCH}" = "64" ] ; then
|
else # test wget a bit
|
||||||
expected=$(cat "$( cd "$(dirname "$0")" ; pwd -P )/../ghc-8.10.3-linux.files" | sort)
|
|
||||||
actual=$(cd "${GHCUP_DIR}/ghc/8.10.3/" && find | sort)
|
|
||||||
[ "${actual}" = "${expected}" ]
|
|
||||||
unset actual expected
|
|
||||||
fi
|
|
||||||
elif [ "${OS}" = "WINDOWS" ] ; then
|
|
||||||
eghcup prefetch ghc 8.10.3
|
|
||||||
eghcup --offline install ghc 8.10.3
|
|
||||||
expected=$(cat "$( cd "$(dirname "$0")" ; pwd -P )/../ghc-8.10.3-windows.files" | sort)
|
|
||||||
actual=$(cd "${GHCUP_DIR}/ghc/8.10.3/" && find | sort)
|
|
||||||
[ "${actual}" = "${expected}" ]
|
|
||||||
unset actual expected
|
|
||||||
else
|
|
||||||
eghcup prefetch ghc 8.10.3
|
eghcup prefetch ghc 8.10.3
|
||||||
eghcup --offline install ghc 8.10.3
|
eghcup --offline install ghc 8.10.3
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ validateTarballs (TarballFilter etool versionRegex) dls gt = do
|
|||||||
($(logError) $ T.pack $ prettyShow e)
|
($(logError) $ T.pack $ prettyShow e)
|
||||||
liftIO $ exitWith (ExitFailure 2)
|
liftIO $ exitWith (ExitFailure 2)
|
||||||
|
|
||||||
let appstate = AppState (Settings True False Never Curl True GHCupURL False) dirs defaultKeyBindings (GHCupInfo mempty mempty mempty) pfreq
|
let appstate = AppState (Settings True False Never Curl False GHCupURL False) dirs defaultKeyBindings (GHCupInfo mempty mempty mempty) pfreq
|
||||||
|
|
||||||
r <-
|
r <-
|
||||||
runLogger
|
runLogger
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ import qualified Data.Map.Strict as M
|
|||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.IO as T
|
import qualified Data.Text.IO as T
|
||||||
import qualified Data.Text.Encoding as E
|
import qualified Data.Text.Encoding as E
|
||||||
|
import qualified Data.Yaml as Y
|
||||||
|
import qualified Data.Yaml.Pretty as YP
|
||||||
import qualified Text.Megaparsec as MP
|
import qualified Text.Megaparsec as MP
|
||||||
import qualified Text.Megaparsec.Char as MPC
|
import qualified Text.Megaparsec.Char as MPC
|
||||||
|
|
||||||
@@ -105,6 +107,7 @@ data Command
|
|||||||
| Rm (Either RmCommand RmOptions)
|
| Rm (Either RmCommand RmOptions)
|
||||||
| DInfo
|
| DInfo
|
||||||
| Compile CompileCommand
|
| Compile CompileCommand
|
||||||
|
| Config ConfigCommand
|
||||||
| Whereis WhereisOptions WhereisCommand
|
| Whereis WhereisOptions WhereisCommand
|
||||||
| Upgrade UpgradeOpts Bool
|
| Upgrade UpgradeOpts Bool
|
||||||
| ToolRequirements
|
| ToolRequirements
|
||||||
@@ -173,6 +176,8 @@ data RmOptions = RmOptions
|
|||||||
|
|
||||||
data CompileCommand = CompileGHC GHCCompileOptions
|
data CompileCommand = CompileGHC GHCCompileOptions
|
||||||
|
|
||||||
|
data ConfigCommand = ShowConfig | SetConfig String String | InitConfig
|
||||||
|
|
||||||
data GHCCompileOptions = GHCCompileOptions
|
data GHCCompileOptions = GHCCompileOptions
|
||||||
{ targetGhc :: Either Version GitBranch
|
{ targetGhc :: Either Version GitBranch
|
||||||
, bootstrapGhc :: Either Version FilePath
|
, bootstrapGhc :: Either Version FilePath
|
||||||
@@ -408,6 +413,12 @@ com =
|
|||||||
<> footerDoc (Just $ text changeLogFooter)
|
<> footerDoc (Just $ text changeLogFooter)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
<> command
|
||||||
|
"config"
|
||||||
|
( Config
|
||||||
|
<$> info (configP <**> helper)
|
||||||
|
(progDesc "Show or set config" <> footerDoc (Just $ text configFooter))
|
||||||
|
)
|
||||||
<> commandGroup "Other commands:"
|
<> commandGroup "Other commands:"
|
||||||
<> hidden
|
<> hidden
|
||||||
)
|
)
|
||||||
@@ -482,6 +493,17 @@ Examples:
|
|||||||
ghcup prefetch ghc 8.10.5
|
ghcup prefetch ghc 8.10.5
|
||||||
ghcup --offline install ghc 8.10.5|]
|
ghcup --offline install ghc 8.10.5|]
|
||||||
|
|
||||||
|
configFooter :: String
|
||||||
|
configFooter = [s|Examples:
|
||||||
|
|
||||||
|
# show current config
|
||||||
|
ghcup config
|
||||||
|
|
||||||
|
# initialize config
|
||||||
|
ghcup config init
|
||||||
|
|
||||||
|
# set <key> <value> configuration pair
|
||||||
|
ghcup config <key> <value>|]
|
||||||
|
|
||||||
installCabalFooter :: String
|
installCabalFooter :: String
|
||||||
installCabalFooter = [s|Discussion:
|
installCabalFooter = [s|Discussion:
|
||||||
@@ -786,6 +808,19 @@ Examples:
|
|||||||
# build cross compiler
|
# build cross compiler
|
||||||
ghcup compile ghc -j 4 -v 8.4.2 -b 8.2.2 -x armv7-unknown-linux-gnueabihf --config $(pwd)/build.mk -- --enable-unregisterised|]
|
ghcup compile ghc -j 4 -v 8.4.2 -b 8.2.2 -x armv7-unknown-linux-gnueabihf --config $(pwd)/build.mk -- --enable-unregisterised|]
|
||||||
|
|
||||||
|
configP :: Parser ConfigCommand
|
||||||
|
configP = subparser
|
||||||
|
( command "init" initP
|
||||||
|
<> command "set" setP -- [set] KEY VALUE at help lhs
|
||||||
|
<> command "show" showP
|
||||||
|
)
|
||||||
|
<|> argsP -- add show for a single option
|
||||||
|
<|> pure ShowConfig
|
||||||
|
where
|
||||||
|
initP = info (pure InitConfig) (progDesc "Write default config to ~/.ghcup/config.yaml")
|
||||||
|
showP = info (pure ShowConfig) (progDesc "Show current config (default)")
|
||||||
|
setP = info argsP (progDesc "Set config KEY to VALUE")
|
||||||
|
argsP = SetConfig <$> argument str (metavar "KEY") <*> argument str (metavar "VALUE")
|
||||||
|
|
||||||
whereisP :: Parser WhereisCommand
|
whereisP :: Parser WhereisCommand
|
||||||
whereisP = subparser
|
whereisP = subparser
|
||||||
@@ -1258,6 +1293,27 @@ toSettings options = do
|
|||||||
, bShowAllTools = fromMaybe bShowAllTools kShowAllTools
|
, bShowAllTools = fromMaybe bShowAllTools kShowAllTools
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSettings :: UTF8.ByteString -> Settings -> IO Settings
|
||||||
|
updateSettings config settings = do
|
||||||
|
settings' <- runE @'[JSONError] $ lE' JSONDecodeError . first show . Y.decodeEither' $ config
|
||||||
|
|
||||||
|
case settings' of
|
||||||
|
VRight r -> pure $ mergeConf r settings
|
||||||
|
VLeft (V (JSONDecodeError e)) -> do
|
||||||
|
B.hPut stderr ("Error decoding config: " <> (E.encodeUtf8 . T.pack . show $ e))
|
||||||
|
die ""
|
||||||
|
_ -> die "Unexpected error!"
|
||||||
|
where
|
||||||
|
mergeConf :: UserSettings -> Settings -> Settings
|
||||||
|
mergeConf UserSettings{..} Settings{..} =
|
||||||
|
let cache' = fromMaybe cache uCache
|
||||||
|
noVerify' = fromMaybe noVerify uNoVerify
|
||||||
|
keepDirs' = fromMaybe keepDirs uKeepDirs
|
||||||
|
downloader' = fromMaybe downloader uDownloader
|
||||||
|
verbose' = fromMaybe verbose uVerbose
|
||||||
|
urlSource' = fromMaybe urlSource uUrlSource
|
||||||
|
noNetwork' = fromMaybe noNetwork uNoNetwork
|
||||||
|
in Settings cache' noVerify' keepDirs' downloader' verbose' urlSource' noNetwork'
|
||||||
|
|
||||||
upgradeOptsP :: Parser UpgradeOpts
|
upgradeOptsP :: Parser UpgradeOpts
|
||||||
upgradeOptsP =
|
upgradeOptsP =
|
||||||
@@ -1292,6 +1348,12 @@ describe_result = $( LitE . StringL <$>
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
formatConfig :: Settings -> KeyBindings -> String
|
||||||
|
formatConfig settings keybindings = unlines [formatSettings, formatKeybindings]
|
||||||
|
where
|
||||||
|
formatKeybindings = unlines . ("key-bindings:":) . map (" "++) . lines . UTF8.toString . YP.encodePretty yamlConfig $ keybindings
|
||||||
|
formatSettings = UTF8.toString . YP.encodePretty yamlConfig $ settings
|
||||||
|
yamlConfig = YP.setConfCompare compare YP.defConfig
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
@@ -1990,6 +2052,28 @@ Make sure to clean up #{tmpdir} afterwards.|])
|
|||||||
runLogger $ $(logError) $ T.pack $ prettyShow e
|
runLogger $ $(logError) $ T.pack $ prettyShow e
|
||||||
pure $ ExitFailure 9
|
pure $ ExitFailure 9
|
||||||
|
|
||||||
|
Config InitConfig -> do
|
||||||
|
path <- getConfigFilePath
|
||||||
|
writeFile path $ formatConfig settings keybindings
|
||||||
|
runLogger $ $(logDebug) [i|"config.yaml initialized at #{path}|]
|
||||||
|
pure ExitSuccess
|
||||||
|
|
||||||
|
Config ShowConfig -> do
|
||||||
|
putStrLn $ formatConfig settings keybindings
|
||||||
|
pure ExitSuccess
|
||||||
|
|
||||||
|
Config (SetConfig k v) -> do
|
||||||
|
case v of
|
||||||
|
"" -> die "Empty values are not allowed."
|
||||||
|
_ -> do
|
||||||
|
settings' <- updateSettings [i|#{k}: #{v}\n|] settings
|
||||||
|
runLogger $ $(logDebug) $ T.pack $ show settings'
|
||||||
|
|
||||||
|
path <- getConfigFilePath
|
||||||
|
writeFile path $ formatConfig settings' keybindings
|
||||||
|
|
||||||
|
pure ExitSuccess
|
||||||
|
|
||||||
Whereis WhereisOptions{..} (WhereisTool tool (Just (ToolVersion v))) ->
|
Whereis WhereisOptions{..} (WhereisTool tool (Just (ToolVersion v))) ->
|
||||||
runLeanWhereIs (do
|
runLeanWhereIs (do
|
||||||
loc <- liftE $ whereIsTool tool v
|
loc <- liftE $ whereIsTool tool v
|
||||||
|
|||||||
@@ -226,6 +226,7 @@ executable ghcup
|
|||||||
, uri-bytestring ^>=0.3.2.2
|
, uri-bytestring ^>=0.3.2.2
|
||||||
, utf8-string ^>=1.0
|
, utf8-string ^>=1.0
|
||||||
, versions >=4.0.1 && <5.1
|
, versions >=4.0.1 && <5.1
|
||||||
|
, yaml ^>=0.11.4.0
|
||||||
|
|
||||||
if flag(internal-downloader)
|
if flag(internal-downloader)
|
||||||
cpp-options: -DINTERNAL_DOWNLOADER
|
cpp-options: -DINTERNAL_DOWNLOADER
|
||||||
|
|||||||
@@ -300,6 +300,10 @@ installUnpackedGHC path inst ver = do
|
|||||||
setModificationTime dest mtime
|
setModificationTime dest mtime
|
||||||
#else
|
#else
|
||||||
PlatformRequest {..} <- lift getPlatformReq
|
PlatformRequest {..} <- lift getPlatformReq
|
||||||
|
liftIO $ copyDirectoryRecursive path inst $ \source dest -> do
|
||||||
|
mtime <- getModificationTime source
|
||||||
|
copyFile source dest
|
||||||
|
setModificationTime dest mtime
|
||||||
|
|
||||||
let alpineArgs
|
let alpineArgs
|
||||||
| ver >= [vver|8.2.2|], Linux Alpine <- _rPlatform
|
| ver >= [vver|8.2.2|], Linux Alpine <- _rPlatform
|
||||||
|
|||||||
@@ -172,31 +172,21 @@ getBase :: ( MonadReader env m
|
|||||||
-> Excepts '[JSONError] m GHCupInfo
|
-> Excepts '[JSONError] m GHCupInfo
|
||||||
getBase uri = do
|
getBase uri = do
|
||||||
Settings { noNetwork } <- lift getSettings
|
Settings { noNetwork } <- lift getSettings
|
||||||
|
yaml <- lift $ yamlFromCache uri
|
||||||
-- try to download yaml... usually this writes it into cache dir,
|
unless noNetwork $
|
||||||
-- but in some cases not (e.g. when using file://), so we honour
|
handleIO (\e -> warnCache (displayException e))
|
||||||
-- the return filepath, if any
|
. catchE @_ @_ @'[] (\e@(DownloadFailed _) -> warnCache (prettyShow e))
|
||||||
mYaml <- if noNetwork && view (uriSchemeL' % schemeBSL') uri /= "file" -- for file://, let it fall through
|
. reThrowAll @_ @_ @'[DownloadFailed] DownloadFailed
|
||||||
then pure Nothing
|
. smartDl
|
||||||
else handleIO (\e -> warnCache (displayException e) >> pure Nothing)
|
$ uri
|
||||||
. catchE @_ @_ @'[] (\e@(DownloadFailed _) -> warnCache (prettyShow e) >> pure Nothing)
|
|
||||||
. reThrowAll @_ @_ @'[DownloadFailed] DownloadFailed
|
|
||||||
. fmap Just
|
|
||||||
. smartDl
|
|
||||||
$ uri
|
|
||||||
|
|
||||||
-- if we didn't get a filepath from the download, use the cached yaml
|
|
||||||
actualYaml <- maybe (lift $ yamlFromCache uri) pure mYaml
|
|
||||||
lift $ $(logDebug) [i|Decoding yaml at: #{actualYaml}|]
|
|
||||||
|
|
||||||
liftE
|
liftE
|
||||||
. onE_ (onError actualYaml)
|
. onE_ (onError yaml)
|
||||||
. lEM' @_ @_ @'[JSONError] JSONDecodeError
|
. lEM' @_ @_ @'[JSONError] JSONDecodeError
|
||||||
. fmap (first (\e -> [i|#{displayException e}
|
. fmap (first (\e -> [i|#{displayException e}
|
||||||
Consider removing "#{actualYaml}" manually.|]))
|
Consider removing "#{yaml}" manually.|]))
|
||||||
. liftIO
|
. liftIO
|
||||||
. Y.decodeFileEither
|
. Y.decodeFileEither
|
||||||
$ actualYaml
|
$ yaml
|
||||||
where
|
where
|
||||||
-- On error, remove the etags file and set access time to 0. This should ensure the next invocation
|
-- On error, remove the etags file and set access time to 0. This should ensure the next invocation
|
||||||
-- may re-download and succeed.
|
-- may re-download and succeed.
|
||||||
@@ -231,32 +221,28 @@ Consider removing "#{actualYaml}" manually.|]))
|
|||||||
, DigestError
|
, DigestError
|
||||||
]
|
]
|
||||||
m1
|
m1
|
||||||
FilePath
|
()
|
||||||
smartDl uri' = do
|
smartDl uri' = do
|
||||||
json_file <- lift $ yamlFromCache uri'
|
json_file <- lift $ yamlFromCache uri'
|
||||||
let scheme = view (uriSchemeL' % schemeBSL') uri'
|
|
||||||
e <- liftIO $ doesFileExist json_file
|
e <- liftIO $ doesFileExist json_file
|
||||||
currentTime <- liftIO getCurrentTime
|
currentTime <- liftIO getCurrentTime
|
||||||
Dirs { cacheDir } <- lift getDirs
|
if e
|
||||||
|
then do
|
||||||
|
accessTime <- liftIO $ getAccessTime json_file
|
||||||
|
|
||||||
-- for local files, let's short-circuit and ignore access time
|
-- access time won't work on most linuxes, but we can try regardless
|
||||||
if | scheme == "file" -> liftE $ download uri' Nothing cacheDir Nothing True
|
when ((utcTimeToPOSIXSeconds currentTime - utcTimeToPOSIXSeconds accessTime) > 300) $
|
||||||
| e -> do
|
-- no access in last 5 minutes, re-check upstream mod time
|
||||||
accessTime <- liftIO $ getAccessTime json_file
|
dlWithMod currentTime json_file
|
||||||
|
else
|
||||||
-- access time won't work on most linuxes, but we can try regardless
|
dlWithMod currentTime json_file
|
||||||
if | ((utcTimeToPOSIXSeconds currentTime - utcTimeToPOSIXSeconds accessTime) > 300) ->
|
|
||||||
-- no access in last 5 minutes, re-check upstream mod time
|
|
||||||
dlWithMod currentTime json_file
|
|
||||||
| otherwise -> pure json_file
|
|
||||||
| otherwise -> dlWithMod currentTime json_file
|
|
||||||
where
|
where
|
||||||
dlWithMod modTime json_file = do
|
dlWithMod modTime json_file = do
|
||||||
let (dir, fn) = splitFileName json_file
|
let (dir, fn) = splitFileName json_file
|
||||||
f <- liftE $ download uri' Nothing dir (Just fn) True
|
f <- liftE $ download uri' Nothing dir (Just fn) True
|
||||||
liftIO $ setModificationTime f modTime
|
liftIO $ setModificationTime f modTime
|
||||||
liftIO $ setAccessTime f modTime
|
liftIO $ setAccessTime f modTime
|
||||||
pure f
|
|
||||||
|
|
||||||
|
|
||||||
getDownloadInfo :: ( MonadReader env m
|
getDownloadInfo :: ( MonadReader env m
|
||||||
@@ -318,25 +304,27 @@ download :: ( MonadReader env m
|
|||||||
)
|
)
|
||||||
=> URI
|
=> URI
|
||||||
-> Maybe T.Text -- ^ expected hash
|
-> Maybe T.Text -- ^ expected hash
|
||||||
-> FilePath -- ^ destination dir (ignored for file:// scheme)
|
-> FilePath -- ^ destination dir
|
||||||
-> Maybe FilePath -- ^ optional filename
|
-> Maybe FilePath -- ^ optional filename
|
||||||
-> Bool -- ^ whether to read an write etags
|
-> Bool -- ^ whether to read an write etags
|
||||||
-> Excepts '[DigestError , DownloadFailed] m FilePath
|
-> Excepts '[DigestError , DownloadFailed] m FilePath
|
||||||
download uri eDigest dest mfn etags
|
download uri eDigest dest mfn etags
|
||||||
| scheme == "https" = dl
|
| scheme == "https" = dl
|
||||||
| scheme == "http" = dl
|
| scheme == "http" = dl
|
||||||
| scheme == "file" = do
|
| scheme == "file" = cp
|
||||||
let destFile' = T.unpack . decUTF8Safe $ path
|
|
||||||
lift $ $(logDebug) [i|using local file: #{destFile'}|]
|
|
||||||
forM_ eDigest (liftE . flip checkDigest destFile')
|
|
||||||
pure destFile'
|
|
||||||
| otherwise = throwE $ DownloadFailed (variantFromValue UnsupportedScheme)
|
| otherwise = throwE $ DownloadFailed (variantFromValue UnsupportedScheme)
|
||||||
|
|
||||||
where
|
where
|
||||||
scheme = view (uriSchemeL' % schemeBSL') uri
|
scheme = view (uriSchemeL' % schemeBSL') uri
|
||||||
|
cp = do
|
||||||
|
-- destination dir must exist
|
||||||
|
liftIO $ createDirRecursive' dest
|
||||||
|
let fromFile = T.unpack . decUTF8Safe $ path
|
||||||
|
liftIO $ copyFile fromFile destFile
|
||||||
|
pure destFile
|
||||||
dl = do
|
dl = do
|
||||||
destFile <- liftE . reThrowAll @_ @_ @'[DownloadFailed] DownloadFailed $ getDestFile
|
let uri' = decUTF8Safe (serializeURIRef' uri)
|
||||||
lift $ $(logInfo) [i|downloading: #{uri'} as file #{destFile}|]
|
lift $ $(logInfo) [i|downloading: #{uri'}|]
|
||||||
|
|
||||||
-- destination dir must exist
|
-- destination dir must exist
|
||||||
liftIO $ createDirRecursive' dest
|
liftIO $ createDirRecursive' dest
|
||||||
@@ -378,7 +366,7 @@ download uri eDigest dest mfn etags
|
|||||||
_ -> liftE $ throwE @_ @'[DownloadFailed] (DownloadFailed (toVariantAt @0 (MalformedHeaders headers)
|
_ -> liftE $ throwE @_ @'[DownloadFailed] (DownloadFailed (toVariantAt @0 (MalformedHeaders headers)
|
||||||
:: V '[MalformedHeaders]))
|
:: V '[MalformedHeaders]))
|
||||||
|
|
||||||
writeEtags destFile (parseEtags headers)
|
writeEtags (parseEtags headers)
|
||||||
else
|
else
|
||||||
liftE $ lEM @_ @'[ProcessError] $ exec "curl"
|
liftE $ lEM @_ @'[ProcessError] $ exec "curl"
|
||||||
(o' ++ ["-fL", "-o", destFile, T.unpack uri']) Nothing Nothing
|
(o' ++ ["-fL", "-o", destFile, T.unpack uri']) Nothing Nothing
|
||||||
@@ -395,13 +383,13 @@ download uri eDigest dest mfn etags
|
|||||||
case _exitCode of
|
case _exitCode of
|
||||||
ExitSuccess -> do
|
ExitSuccess -> do
|
||||||
liftIO $ copyFile destFileTemp destFile
|
liftIO $ copyFile destFileTemp destFile
|
||||||
writeEtags destFile (parseEtags (decUTF8Safe' _stdErr))
|
writeEtags (parseEtags (decUTF8Safe' _stdErr))
|
||||||
ExitFailure i'
|
ExitFailure i'
|
||||||
| i' == 8
|
| i' == 8
|
||||||
, Just _ <- find (T.pack "304 Not Modified" `T.isInfixOf`) . T.lines . decUTF8Safe' $ _stdErr
|
, Just _ <- find (T.pack "304 Not Modified" `T.isInfixOf`) . T.lines . decUTF8Safe' $ _stdErr
|
||||||
-> do
|
-> do
|
||||||
$logDebug "Not modified, skipping download"
|
$logDebug "Not modified, skipping download"
|
||||||
writeEtags destFile (parseEtags (decUTF8Safe' _stdErr))
|
writeEtags (parseEtags (decUTF8Safe' _stdErr))
|
||||||
| otherwise -> throwE (NonZeroExit i' "wget" opts)
|
| otherwise -> throwE (NonZeroExit i' "wget" opts)
|
||||||
else do
|
else do
|
||||||
let opts = o' ++ ["-O", destFileTemp , T.unpack uri']
|
let opts = o' ++ ["-O", destFileTemp , T.unpack uri']
|
||||||
@@ -416,10 +404,10 @@ download uri eDigest dest mfn etags
|
|||||||
let addHeaders = maybe mempty (\etag -> M.fromList [ (mk . E.encodeUtf8 . T.pack $ "If-None-Match"
|
let addHeaders = maybe mempty (\etag -> M.fromList [ (mk . E.encodeUtf8 . T.pack $ "If-None-Match"
|
||||||
, E.encodeUtf8 etag)]) metag
|
, E.encodeUtf8 etag)]) metag
|
||||||
liftE
|
liftE
|
||||||
$ catchE @HTTPNotModified @'[DownloadFailed] @'[] (\(HTTPNotModified etag) -> lift $ writeEtags destFile (pure $ Just etag))
|
$ catchE @HTTPNotModified @'[DownloadFailed] @'[] (\(HTTPNotModified etag) -> lift $ writeEtags (pure $ Just etag))
|
||||||
$ do
|
$ do
|
||||||
r <- downloadToFile https host fullPath port destFile addHeaders
|
r <- downloadToFile https host fullPath port destFile addHeaders
|
||||||
writeEtags destFile (pure $ decUTF8Safe <$> getHeader r "etag")
|
writeEtags (pure $ decUTF8Safe <$> getHeader r "etag")
|
||||||
else void $ liftE $ catchE @HTTPNotModified
|
else void $ liftE $ catchE @HTTPNotModified
|
||||||
@'[DownloadFailed]
|
@'[DownloadFailed]
|
||||||
(\e@(HTTPNotModified _) ->
|
(\e@(HTTPNotModified _) ->
|
||||||
@@ -432,18 +420,12 @@ download uri eDigest dest mfn etags
|
|||||||
|
|
||||||
|
|
||||||
-- Manage to find a file we can write the body into.
|
-- Manage to find a file we can write the body into.
|
||||||
getDestFile :: Monad m => Excepts '[NoUrlBase] m FilePath
|
destFile :: FilePath
|
||||||
getDestFile =
|
destFile = maybe (dest </> T.unpack (decUTF8Safe (urlBaseName path)))
|
||||||
case mfn of
|
(dest </>)
|
||||||
Just fn -> pure (dest </> fn)
|
mfn
|
||||||
Nothing
|
|
||||||
| let urlBase = T.unpack (decUTF8Safe (urlBaseName path))
|
|
||||||
, not (null urlBase) -> pure (dest </> urlBase)
|
|
||||||
-- TODO: remove this once we use hpath again
|
|
||||||
| otherwise -> throwE $ NoUrlBase uri'
|
|
||||||
|
|
||||||
path = view pathL' uri
|
path = view pathL' uri
|
||||||
uri' = decUTF8Safe (serializeURIRef' uri)
|
|
||||||
|
|
||||||
parseEtags :: (MonadLogger m, MonadIO m, MonadThrow m) => T.Text -> m (Maybe T.Text)
|
parseEtags :: (MonadLogger m, MonadIO m, MonadThrow m) => T.Text -> m (Maybe T.Text)
|
||||||
parseEtags stderr = do
|
parseEtags stderr = do
|
||||||
@@ -462,8 +444,8 @@ download uri eDigest dest mfn etags
|
|||||||
$logDebug "No etags header found"
|
$logDebug "No etags header found"
|
||||||
pure Nothing
|
pure Nothing
|
||||||
|
|
||||||
writeEtags :: (MonadLogger m, MonadIO m, MonadThrow m) => FilePath -> m (Maybe T.Text) -> m ()
|
writeEtags :: (MonadLogger m, MonadIO m, MonadThrow m) => m (Maybe T.Text) -> m ()
|
||||||
writeEtags destFile getTags = do
|
writeEtags getTags = do
|
||||||
getTags >>= \case
|
getTags >>= \case
|
||||||
Just t -> do
|
Just t -> do
|
||||||
$logDebug [i|Writing etagsFile #{(etagsFile destFile)}|]
|
$logDebug [i|Writing etagsFile #{(etagsFile destFile)}|]
|
||||||
|
|||||||
@@ -327,15 +327,6 @@ instance Pretty UnexpectedListLength where
|
|||||||
|
|
||||||
instance Exception UnexpectedListLength
|
instance Exception UnexpectedListLength
|
||||||
|
|
||||||
data NoUrlBase = NoUrlBase Text
|
|
||||||
deriving Show
|
|
||||||
|
|
||||||
instance Pretty NoUrlBase where
|
|
||||||
pPrint (NoUrlBase url) =
|
|
||||||
text [i|Couldn't get a base filename from url #{url}|]
|
|
||||||
|
|
||||||
instance Exception NoUrlBase
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
------------------------
|
------------------------
|
||||||
|
|||||||
@@ -316,3 +316,6 @@ deriveJSON defaultOptions { sumEncoding = ObjectWithSingleField } ''URLSource
|
|||||||
deriveJSON defaultOptions { sumEncoding = ObjectWithSingleField } ''Key
|
deriveJSON defaultOptions { sumEncoding = ObjectWithSingleField } ''Key
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = \str' -> maybe str' T.unpack . T.stripPrefix (T.pack "k-") . T.pack . kebab $ str' } ''UserKeyBindings
|
deriveJSON defaultOptions { fieldLabelModifier = \str' -> maybe str' T.unpack . T.stripPrefix (T.pack "k-") . T.pack . kebab $ str' } ''UserKeyBindings
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = \str' -> maybe str' T.unpack . T.stripPrefix (T.pack "u-") . T.pack . kebab $ str' } ''UserSettings
|
deriveJSON defaultOptions { fieldLabelModifier = \str' -> maybe str' T.unpack . T.stripPrefix (T.pack "u-") . T.pack . kebab $ str' } ''UserSettings
|
||||||
|
|
||||||
|
deriveToJSON defaultOptions { fieldLabelModifier = kebab } ''Settings
|
||||||
|
deriveToJSON defaultOptions { fieldLabelModifier = drop 2 . kebab } ''KeyBindings -- move under key-bindings key
|
||||||
|
|||||||
Reference in New Issue
Block a user