Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Hoogle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
haskell
Hoogle
Commits
6067c110
Unverified
Commit
6067c110
authored
2 years ago
by
Neil Mitchell
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #395 from Profpatsch/refactor-download-code
Refactor Input/Download
parents
ee04e129
6c535bb6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Action/Generate.hs
+8
-3
8 additions, 3 deletions
src/Action/Generate.hs
src/Input/Download.hs
+24
-9
24 additions, 9 deletions
src/Input/Download.hs
with
32 additions
and
12 deletions
src/Action/Generate.hs
+
8
−
3
View file @
6067c110
...
...
@@ -201,14 +201,19 @@ actionGenerate g@Generate{..} = withTiming (if debug then Just $ replaceExtensio
createDirectoryIfMissing
True
$
takeDirectory
database
whenLoud
$
putStrLn
$
"Generating files to "
++
takeDirectory
database
download
<-
pure
$
downloadInput
timing
insecure
download
(
takeDirectory
database
)
let
doDownload
name
url
=
do
let
download'
=
case
download
of
Just
True
->
AlwaysDownloadInput
Just
False
->
NeverDownloadInput
Nothing
->
DownloadInputIfNotThere
downloadInput
timing
insecure
download'
(
takeDirectory
database
)
name
url
settings
<-
loadSettings
(
cbl
,
want
,
source
)
<-
case
language
of
Haskell
|
Just
dir
<-
haddock
->
readHaskellHaddock
timing
settings
dir
|
[
""
]
<-
local_
->
readHaskellGhcpkg
timing
settings
|
[]
<-
local_
->
readHaskellOnline
timing
settings
download
|
[]
<-
local_
->
readHaskellOnline
timing
settings
do
Do
wnload
|
otherwise
->
readHaskellDirs
timing
settings
local_
Frege
|
[]
<-
local_
->
readFregeOnline
timing
download
Frege
|
[]
<-
local_
->
readFregeOnline
timing
do
Do
wnload
|
otherwise
->
errorIO
"No support for local Frege databases"
(
cblErrs
,
popularity
)
<-
evaluate
$
packagePopularity
cbl
cbl
<-
evaluate
$
Map
.
map
(
\
p
->
p
{
packageDepends
=
[]
})
cbl
-- clear the memory, since the information is no longer used
...
...
This diff is collapsed.
Click to expand it.
src/Input/Download.hs
+
24
−
9
View file @
6067c110
{-# LANGUAGE TupleSections #-}
module
Input.Download
(
downloadInput
)
where
module
Input.Download
(
downloadInput
,
DownloadInput
(
..
)
)
where
import
System.FilePath
import
Control.Monad.Extra
...
...
@@ -14,24 +14,39 @@ import General.Timing
import
Control.Monad.Trans.Resource
import
Control.Exception.Extra
data
DownloadInput
=
AlwaysDownloadInput
|
NeverDownloadInput
|
DownloadInputIfNotThere
-- | Download all the input files to input/
downloadInput
::
Timing
->
Bool
->
Maybe
Bool
->
FilePath
->
String
->
URL
->
IO
FilePath
downloadInput
::
Timing
->
Bool
->
DownloadInput
->
FilePath
->
String
->
URL
->
IO
FilePath
downloadInput
timing
insecure
download
dir
name
url
=
do
let
file
=
dir
</>
"input-"
++
name
exists
<-
doesFileExist
file
when
(
not
exists
&&
download
==
Just
False
)
$
errorIO
$
"File is not already downloaded and --download=no given, downloading "
++
url
++
" to "
++
file
when
(
not
exists
||
download
==
Just
True
)
$
timed
timing
(
"Downloading "
++
url
)
$
do
downloadFile
insecure
(
file
<.>
"part"
)
url
renameFile
(
file
<.>
"part"
)
file
let
act
=
timed
timing
(
"Downloading "
++
url
)
$
do
downloadFile
insecure
(
file
<.>
"part"
)
url
renameFile
(
file
<.>
"part"
)
file
case
download
of
NeverDownloadInput
->
unless
exists
$
errorIO
$
"File is not already downloaded and --download=no given, downloading "
++
url
++
" to "
++
file
AlwaysDownloadInput
->
act
DownloadInputIfNotThere
->
unless
exists
act
pure
file
downloadFile
::
Bool
->
FilePath
->
String
->
IO
()
downloadFile
insecure
file
url
=
do
let
request
=
C
.
parseRequest_
url
manager
<-
C
.
newManager
$
C
.
mkManagerSettings
(
TLSSettingsSimple
insecure
False
False
)
Nothing
manager
<-
C
.
newManager
$
C
.
mkManagerSettings
(
TLSSettingsSimple
{
settingDisableCertificateValidation
=
insecure
,
settingDisableSession
=
False
,
settingUseServerName
=
False
})
Nothing
runResourceT
$
do
response
<-
C
.
http
request
manager
C
.
runConduit
$
C
.
responseBody
response
C
..|
sinkFile
file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment