Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
walint
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
hub
walint
Commits
eb214ab0
Unverified
Commit
eb214ab0
authored
3 years ago
by
stuebinm
Browse files
Options
Downloads
Patches
Plain Diff
check if assets exist
parent
b3bb2e8a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/CheckDir.hs
+40
-8
40 additions, 8 deletions
lib/CheckDir.hs
with
40 additions
and
8 deletions
lib/CheckDir.hs
+
40
−
8
View file @
eb214ab0
...
...
@@ -10,7 +10,7 @@ module CheckDir (recursiveCheckDir) where
import
CheckMap
(
MapResult
(
mapresultProvides
),
loadAndLintMap
,
mapresultDepends
)
import
Control.Monad
(
void
)
import
Control.Monad
(
void
,
foldM
)
import
Control.Monad.Extra
(
mapMaybeM
)
import
Data.Aeson
(
ToJSON
,
(
.=
))
import
qualified
Data.Aeson
as
A
...
...
@@ -25,8 +25,11 @@ import Paths (normalise, normaliseWithFrag)
import
System.FilePath
(
splitPath
,
(
</>
))
import
qualified
System.FilePath
as
FP
import
System.FilePath.Posix
(
takeDirectory
)
import
Types
(
Dep
(
LocalMap
),
Level
)
import
Types
(
Dep
(
LocalMap
,
Local
),
Level
)
import
Util
(
PrettyPrint
(
prettyprint
))
import
Data.Foldable
(
fold
)
import
Data.Functor
((
<&>
))
import
System.Directory.Extra
(
doesFileExist
)
-- based on the startling observation that Data.Map has lower complexity
...
...
@@ -41,6 +44,7 @@ listFromSet = map fst . M.toList
data
DirResult
=
DirResult
{
dirresultMaps
::
Map
FilePath
MapResult
,
dirresultDeps
::
[
MissingDep
]
,
dirresultMissingAssets
::
[
MissingAsset
]
}
deriving
(
Generic
)
data
MissingDep
=
MissingDep
...
...
@@ -48,12 +52,22 @@ data MissingDep = MissingDep
,
neededBy
::
[
FilePath
]
}
deriving
(
Generic
,
ToJSON
)
newtype
MissingAsset
=
MissingAsset
MissingDep
instance
ToJSON
DirResult
where
toJSON
res
=
A
.
object
[
"missingDeps"
.=
dirresultDeps
res
,
"missingAssets"
.=
dirresultMissingAssets
res
,
"mapLints"
.=
dirresultMaps
res
]
instance
ToJSON
MissingAsset
where
toJSON
(
MissingAsset
md
)
=
A
.
object
[
"asset"
.=
entrypoint
md
,
"neededBy"
.=
neededBy
md
]
instance
PrettyPrint
(
Level
,
DirResult
)
where
prettyprint
(
level
,
res
)
=
prettyMapLints
<>
prettyMissingDeps
where
...
...
@@ -79,12 +93,15 @@ instance Semigroup DirResult where
a
<>
b
=
DirResult
{
dirresultMaps
=
dirresultMaps
a
<>
dirresultMaps
b
,
dirresultDeps
=
dirresultDeps
a
<>
dirresultDeps
b
,
dirresultMissingAssets
=
dirresultMissingAssets
a
<>
dirresultMissingAssets
b
}
instance
Monoid
DirResult
where
mempty
=
DirResult
{
dirresultMaps
=
mempty
,
dirresultDeps
=
[]
,
dirresultDeps
=
mempty
,
dirresultMissingAssets
=
mempty
}
...
...
@@ -95,7 +112,10 @@ instance Monoid DirResult where
recursiveCheckDir
::
FilePath
->
FilePath
->
IO
DirResult
recursiveCheckDir
prefix
root
=
do
linted
<-
recursiveCheckDir'
prefix
[
root
]
mempty
mempty
pure
$
linted
<>
mempty
{
dirresultDeps
=
missingDeps
linted
}
mAssets
<-
missingAssets
prefix
linted
pure
$
linted
<>
mempty
{
dirresultDeps
=
missingDeps
linted
,
dirresultMissingAssets
=
mAssets
}
-- | Given a (partially) completed DirResult, check which local
...
...
@@ -123,6 +143,20 @@ missingDeps res =
-- each map file is an entrypoint by itself
trivial
=
mapKeys
T
.
pack
$
void
(
dirresultMaps
res
)
-- | Checks if all assets found (contained in the map's lints)
-- actually exist where they should exist
missingAssets
::
FilePath
->
DirResult
->
IO
[
MissingAsset
]
missingAssets
prefix
res
=
mapM
(
fmap
(
fmap
(
fmap
MissingAsset
))
missingOfMap
)
(
M
.
toList
.
dirresultMaps
$
res
)
<&>
fold
where
missingOfMap
(
path
,
mapres
)
=
mapMaybeM
(
\
case
Local
relpath
->
let
asset
=
normalise
(
takeDirectory
path
)
relpath
in
doesFileExist
(
prefix
</>
asset
)
<&>
\
case
True
->
Nothing
False
->
Just
$
MissingDep
(
T
.
pack
asset
)
[
path
]
_
->
pure
Nothing
)
(
mapresultDepends
mapres
)
-- | The less-nice function for checking an entire repository.
--
...
...
@@ -145,7 +179,7 @@ recursiveCheckDir' prefix paths done acc = do
(
\
(
m
,
res
)
->
let
ps
=
mapMaybe
(
\
case
{
LocalMap
p
->
Just
p
;
_
->
Nothing
})
(
mapresultDepends
$
res
)
(
mapresultDepends
res
)
in
map
(
FP
.
normalise
.
normalise
(
takeDirectory
m
))
ps
)
lints
...
...
@@ -160,9 +194,7 @@ recursiveCheckDir' prefix paths done acc = do
let
knowns
=
M
.
union
done
$
setFromList
paths
-- Monoids!
let
acc'
=
acc
<>
DirResult
{
dirresultMaps
=
M
.
fromList
lints
,
dirresultDeps
=
[]
}
let
acc'
=
acc
<>
mempty
{
dirresultMaps
=
M
.
fromList
lints
}
-- Tail recursion!
case
unknowns
of
[]
->
pure
acc'
...
...
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