Comments (4)
oh, and sometimes, but not usually, I see this output:
2012-07-12 09:42 watch[68012] (CarbonCore.framework) FSEventStreamStart(): failed assertion 'streamRef != NULL'
from hfsnotify.
I'm not entirely sure what has gone awry with the code, but the following refactoring works properly with both action and chan (one is commented out and one is called upon in the coffee function).
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (FilePath)
import Control.Concurrent
import Control.Monad (forever)
import Data.Text
import Filesystem
import Filesystem.Path.CurrentOS
import System.Cmd (rawSystem)
import System.IO.FSNotify
main :: IO ()
main = do
wd <- getWorkingDirectory
withManager $ \man -> coffee man wd
void
coffee :: WatchManager -> FilePath -> IO ()
coffee man dir = do
-- guardExt method:
guardExt man dir "coffee" "js" doAction
_ <- getLine
void
-- guardExtChan method:
-- tid <- guardExtChan man dir "coffee" "js" doAcdtion
-- _ <- getLine
-- killThread tid
void :: IO ()
void = return ()
-- | assumes you are running a compile function that produces a file in the same directory but with a different extension
guardExt :: WatchManager
-> FilePath -- ^ Directory to watch
-> Text -- ^ old extension
-> Text -- ^ new extension
-> (FilePath -> IO ()) -- ^ compile action to run on file
-> IO ()
guardExt man dir oldExt newExt action = do
print $ dir
watchTreeAction man dir (predicate oldExt) (compile newExt action)
where
readChanLoop :: Chan Event -> Text -> (FilePath -> IO ()) -> IO ()
readChanLoop chan newExt action = do
event <- readChan chan
case event of
Added f _ -> actionWrapper newExt action f
Modified f _ -> actionWrapper newExt action f
Removed f _ -> void
-- | for debugging
guardExtChan :: WatchManager
-> FilePath -- ^ Directory to watch
-> Text -- ^ old extension
-> Text -- ^ new extension
-> (FilePath -> IO ()) -- ^ compile action to run on file
-> IO ThreadId
guardExtChan man dir oldExt newExt action = do
chan <- newChan
watchTreeChan man dir (predicate oldExt) chan
forkIO $ forever (readChanLoop chan newExt action)
doAction fp =
-- Debug:
putStrLn $ "Dispatching on: " ++ show fp
-- Do stuff:
-- rawSystem "coffee" ["-c", encodeString fp] >> void
actionWrapper newExt action f = do
print f
print $ convert newExt f
action . (convert newExt) $ f
extFilter oldExt = flip hasExtension oldExt
convert newExt = flip replaceExtension newExt
compile newExt action event = do
print event
case event of
Added f _ -> actionWrapper newExt action f
Modified f _ -> actionWrapper newExt action f
Removed f _ -> void
predicate oldExt event =
case event of
Added f _ -> extFilter oldExt f
Modified f _ -> extFilter oldExt f
Removed f _ -> extFilter oldExt f
from hfsnotify.
This works great in the root watched directory. However, watchTree is not picking up my recurse directories.
from hfsnotify.
recursive working now also.
from hfsnotify.
Related Issues (20)
- removeWatch: invalid argument (Bad file descriptor)
- Likely O(n^2) behaviour for `watchTree` HOT 17
- 0.4 release HOT 17
- stuck when compiling HOT 13
- Build failure on FreeBSD HOT 14
- Problems with fsnotify-0.4.0.1 on Windows HOT 6
- System.FSNotify does not export type WatchConfig HOT 9
- Build failure on windows for fsnotify-0.4.0.1 HOT 1
- Terminating steeloverseer+tmux triggers "Error removing watch:" HOT 2
- No modification notifications for symlinks HOT 5
- Doesn't work on macOS unless -N is specified HOT 1
- Allow debouncing regardless of if event is same file HOT 5
- Exceptions in Action gets swallowed HOT 7
- Drop shelly dependency HOT 1
- Does creation/deletion of a hard-link trigger a modification event? HOT 2
- Windows 10, no Event unless Pulling is forced. HOT 6
- Debounce config works in very unexpected way (only on Win32) HOT 1
- When events fire too quickly, the whole watch stops HOT 1
- `watchDir` misses some Git events, `watchTree` shows them all on Linux HOT 6
- Fire event variety "CloseWrite" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hfsnotify.