Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
ghcup-hs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Haskell
ghcup-hs
Merge requests
!137
Fix metadata download
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Fix metadata download
fix-metadata-download
into
master
Overview
0
Commits
4
Pipelines
4
Changes
1
Merged
Julian Ospald
requested to merge
fix-metadata-download
into
master
3 years ago
Overview
0
Commits
4
Pipelines
4
Changes
1
Expand
0
0
Merge request reports
Compare
master
version 3
92dc1ab3
3 years ago
version 2
72133d00
3 years ago
version 1
b6d2a636
3 years ago
master (base)
and
latest version
latest version
6dfc04a9
4 commits,
3 years ago
version 3
92dc1ab3
4 commits,
3 years ago
version 2
72133d00
3 commits,
3 years ago
version 1
b6d2a636
3 commits,
3 years ago
1 file
+
42
−
30
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
lib/GHCup/Download.hs
+
42
−
30
Options
@@ -172,21 +172,31 @@ getBase :: ( MonadReader env m
->
Excepts
'
[
JSONError
]
m
GHCupInfo
getBase
uri
=
do
Settings
{
noNetwork
}
<-
lift
getSettings
yaml
<-
lift
$
yamlFromCache
uri
unless
noNetwork
$
handleIO
(
\
e
->
warnCache
(
displayException
e
))
.
catchE
@
_
@
_
@
'
[]
(
\
e
@
(
DownloadFailed
_
)
->
warnCache
(
prettyShow
e
))
.
reThrowAll
@
_
@
_
@
'
[
DownloadFailed
]
DownloadFailed
.
smartDl
$
uri
-- try to download yaml... usually this writes it into cache dir,
-- but in some cases not (e.g. when using file://), so we honour
-- the return filepath, if any
mYaml
<-
if
noNetwork
&&
view
(
uriSchemeL'
%
schemeBSL'
)
uri
/=
"file"
-- for file://, let it fall through
then
pure
Nothing
else
handleIO
(
\
e
->
warnCache
(
displayException
e
)
>>
pure
Nothing
)
.
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
.
onE_
(
onError
y
aml
)
.
onE_
(
onError
actualY
aml
)
.
lEM'
@
_
@
_
@
'
[
JSONError
]
JSONDecodeError
.
fmap
(
first
(
\
e
->
[
i
|
#{displayException e}
Consider removing "#{
y
aml}" manually.
|]
))
Consider removing "#{
actualY
aml}" manually.
|]
))
.
liftIO
.
Y
.
decodeFileEither
$
y
aml
$
actualY
aml
where
-- On error, remove the etags file and set access time to 0. This should ensure the next invocation
-- may re-download and succeed.
@@ -221,28 +231,32 @@ Consider removing "#{yaml}" manually.|]))
,
DigestError
]
m1
()
FilePath
smartDl
uri'
=
do
json_file
<-
lift
$
yamlFromCache
uri'
let
scheme
=
view
(
uriSchemeL'
%
schemeBSL'
)
uri'
e
<-
liftIO
$
doesFileExist
json_file
currentTime
<-
liftIO
getCurrentTime
if
e
then
do
accessTime
<-
liftIO
$
getAccessTime
json_file
-- access time won't work on most linuxes, but we can try regardless
when
((
utcTimeToPOSIXSeconds
currentTime
-
utcTimeToPOSIXSeconds
accessTime
)
>
300
)
$
-- no access in last 5 minutes, re-check upstream mod time
dlWithMod
currentTime
json_file
else
dlWithMod
currentTime
json_file
Dirs
{
cacheDir
}
<-
lift
getDirs
-- for local files, let's short-circuit and ignore access time
if
|
scheme
==
"file"
->
liftE
$
download
uri'
Nothing
cacheDir
Nothing
True
|
e
->
do
accessTime
<-
liftIO
$
getAccessTime
json_file
-- access time won't work on most linuxes, but we can try regardless
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
dlWithMod
modTime
json_file
=
do
let
(
dir
,
fn
)
=
splitFileName
json_file
f
<-
liftE
$
download
uri'
Nothing
dir
(
Just
fn
)
True
liftIO
$
setModificationTime
f
modTime
liftIO
$
setAccessTime
f
modTime
pure
f
getDownloadInfo
::
(
MonadReader
env
m
@@ -304,24 +318,22 @@ download :: ( MonadReader env m
)
=>
URI
->
Maybe
T
.
Text
-- ^ expected hash
->
FilePath
-- ^ destination dir
->
FilePath
-- ^ destination dir
(ignored for file:// scheme)
->
Maybe
FilePath
-- ^ optional filename
->
Bool
-- ^ whether to read an write etags
->
Excepts
'
[
DigestError
,
DownloadFailed
]
m
FilePath
download
uri
eDigest
dest
mfn
etags
|
scheme
==
"https"
=
dl
|
scheme
==
"http"
=
dl
|
scheme
==
"file"
=
cp
|
scheme
==
"file"
=
do
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
)
where
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
let
uri'
=
decUTF8Safe
(
serializeURIRef'
uri
)
lift
$
$
(
logInfo
)
[
i
|
downloading: #{uri'}
|]
Loading