Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
decker-production
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
Container Registry
Model registry
Operate
Environments
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
HCI-Development
decker-production
Commits
17ec90c3
Commit
17ec90c3
authored
7 years ago
by
Henrik Tramberend
Browse files
Options
Downloads
Patches
Plain Diff
Replace active file eatching with event based FSNotify
parent
2a211c0c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
slides.cabal
+2
-1
2 additions, 1 deletion
slides.cabal
src/pandoc.hs
+3
-0
3 additions, 0 deletions
src/pandoc.hs
src/utilities.hs
+3
-22
3 additions, 22 deletions
src/utilities.hs
src/watch.hs
+45
-0
45 additions, 0 deletions
src/watch.hs
with
53 additions
and
23 deletions
slides.cabal
+
2
−
1
View file @
17ec90c3
...
...
@@ -15,7 +15,7 @@ cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: Pandoc, Test, Embed, Context, Utilities, Filter, Student, Shuffle
exposed-modules:
Watch,
Pandoc, Test, Embed, Context, Utilities, Filter, Student, Shuffle
build-depends: base
, aeson
, random
...
...
@@ -49,6 +49,7 @@ library
, http-types
, highlighting-kate
, multimap
, fsnotify
default-language: Haskell2010
executable decker
...
...
This diff is collapsed.
Click to expand it.
src/pandoc.hs
+
3
−
0
View file @
17ec90c3
...
...
@@ -11,6 +11,7 @@ import qualified Data.HashMap.Strict as H
import
Data.List
import
Data.Maybe
import
qualified
Data.Map
as
M
import
qualified
Data.Text
as
T
import
qualified
Data.MultiMap
as
MM
import
Data.Digest.Pure.MD5
import
qualified
Data.Yaml
as
Y
...
...
@@ -66,3 +67,5 @@ readMetaData metaFiles =
joinMeta
::
Y
.
Value
->
Y
.
Value
->
Y
.
Value
joinMeta
(
Y
.
Object
old
)
(
Y
.
Object
new
)
=
Y
.
Object
(
H
.
union
new
old
)
joinMeta
_
_
=
throw
$
YamlException
"Can only join YAML objects."
-- extractMetaDataFromMarkdown :: T.Text -> Y.Value
This diff is collapsed.
Click to expand it.
src/utilities.hs
+
3
−
22
View file @
17ec90c3
...
...
@@ -4,11 +4,9 @@ module Utilities
,
terminate
,
threadDelay'
,
wantRepeat
,
waitForModificationIn
,
defaultContext
,
runShakeInContext
,
watchFiles
,
waitForTwitch
,
dropSuffix
,
stopServer
,
startServer
...
...
@@ -50,6 +48,7 @@ import Control.Exception
import
Development.Shake
import
Development.Shake.FilePath
as
SFP
import
Data.Dynamic
import
Data.List
import
Data.List.Extra
import
Data.Maybe
import
Data.IORef
...
...
@@ -87,6 +86,7 @@ import Network.URI
import
Text.Highlighting.Kate.Styles
import
Context
import
Embed
import
Watch
-- Find the project directory and change current directory to there.
-- The project directory is the first upwards directory that contains a .git directory entry.
...
...
@@ -170,9 +170,6 @@ threadDelay' = liftIO . threadDelay
wantRepeat
::
IORef
Bool
->
Action
()
wantRepeat
justOnce
=
liftIO
$
writeIORef
justOnce
False
waitForModificationIn
::
[
FilePath
]
->
Action
()
waitForModificationIn
=
liftIO
.
waitForTwitch
-- The context of program invocation consists of a list of
-- files to watch and a possibly running local http server.
data
Context
=
...
...
@@ -201,27 +198,11 @@ runShakeInContext context options rules = do
if
null
files
then
return
True
else
do
waitForTwitch
files
waitForTwitch
Passive
files
return
False
watchFiles
=
setFilesToWatch
-- | Actively waits for the first change to any member in the set of specified
-- | files and their parent directories, then returns.
waitForTwitch
files
=
do
startTime
<-
getCurrentTime
let
dirs
=
map
takeDirectory
files
let
filesAndDirs
=
Set
.
toList
.
Set
.
fromList
$
files
++
dirs
whileM_
(
noModificationSince
startTime
filesAndDirs
)
(
threadDelay
300000
)
where
noModificationSince
startTime
pathes
=
do
modified
<-
mapM
(
modifiedSince
startTime
)
pathes
return
$
not
(
or
modified
)
modifiedSince
time
path
=
handle
(
\
(
SomeException
_
)
->
return
False
)
$
do
modTime
<-
getModificationTime
path
return
$
diffUTCTime
modTime
time
>
0
-- | Monadic version of list concatenation.
(
<++>
)
::
Monad
m
...
...
This diff is collapsed.
Click to expand it.
src/watch.hs
0 → 100644
+
45
−
0
View file @
17ec90c3
module
Watch
(
waitForTwitchPassive
)
where
-- | A non-polling file watcher based on fsnotify
import
Data.List
import
System.FilePath
import
System.FilePath.Glob
import
Control.Concurrent.MVar
import
System.FSNotify
-- | Wait for something to happen on one of the matching files
-- in one of the supplied directories.
waitForTwitch
::
[
FilePath
]
->
[
Pattern
]
->
IO
FilePath
waitForTwitch
directories
patterns
=
do
done
<-
newEmptyMVar
mgr
<-
startManager
stops
<-
watchIt
mgr
done
filepath
<-
takeMVar
done
sequence_
stops
stopManager
mgr
return
filepath
where
-- Match a filepath against the supplied patterns
isWatchedFile
event
=
any
((
flip
match
)
(
eventPath
event
))
patterns
-- Stop the watch manager and notify the main thread
stopWatching
mgr
done
event
=
do
putMVar
done
(
eventPath
event
)
-- Watch everything within the supplied dirs
watchInDir
mgr
done
dir
=
watchTree
mgr
dir
isWatchedFile
(
stopWatching
mgr
done
)
watchIt
mgr
done
=
do
mapM
(
watchInDir
mgr
done
)
directories
twitchPatterns
=
map
compile
[
"**/*.md"
,
"**/*.yaml"
,
"**/*.png"
,
"**/*.jpg"
]
waitForTwitchPassive
files
=
do
let
dirs
=
nub
(
map
takeDirectory
files
)
waitForTwitch
dirs
twitchPatterns
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