delta-0.2.1.2: A library for detecting file changes

Copyright(c) Christof Schramm 2015
LicenseLGPL v2
MaintainerChristof Schramm
StabilityExperimental
Safe HaskellNone
LanguageHaskell2010

System.Delta

Contents

Description

Description

An umberella package for the delta library. This library can be used to monitor changed new deleted files in a given directory (or set of directories).

On non OS X systems this library polls the directories of interest recursively in certain intervals, but I will add OS-specific functionality to monitor the filesystem.

On OS X this library can use the File System Events API to detect changes without recursive directory traversal.

Examples

Create a watcher that prints a line if a new file is created in the monitored directory:

printNewFilePaths basePath = do
  watcher <- deltaDirWithCallbacks basePath
  withNewCallback watcher (\x -> putStrLn $ "new file: " ++ x)

Synopsis

Documentation

Important functions

deltaDir :: FilePath -> IO FileWatcher Source

Build a file watcher, the concrete implementation is operating system dependent.

  • The default uses polling (createPollWatcher)
  • The watcher for OS X uses the FS Events API createFSEventsWatcher

deltaDirWithCallbacks :: FilePath -> IO CallbackWatcher Source

Build a file watcher that allows to register callbacks

FRP based interface

data FileWatcher Source

A type for watching a directory based on functional reactive programming At the core of this class are three event streams:

  • changedFiles is a stream of canonicalized FilePaths on changed files
  • newFiles is a stream of canonicalized FilePaths of newly created files
  • deletedFiles is a stream of canonicalized FilePaths of deleted files

Constructors

FileWatcher 

Fields

newFiles :: Event FilePath

Newly created files, renamed files

deletedFiles :: Event FilePath

Deleted files, renamed files

changedFiles :: Event FilePath

Changed files

cleanUpAndClose :: IO ()

A function to clean and close ^ this watcher

Callback based interface

data CallbackWatcher Source

Provides a callback based interface to an FRP base FileWatcher

data CallbackId Source

Id of a callback in a CallbackWatcher

withCallbacks :: FileWatcher -> IO CallbackWatcher Source

Wrap a file watcher in a datatype that allows adding callbacks

Adding callbacks

withDeleteCallback Source

Arguments

:: CallbackWatcher 
-> (FilePath -> IO ())

An IO action on the deleted path

-> IO CallbackId 

Add a callback that is executed when file deletion is detected

withChangedCallback Source

Arguments

:: CallbackWatcher 
-> (FilePath -> IO ())

Action on changed file

-> IO CallbackId 

Add a callback on a changed file

withNewCallback Source

Arguments

:: CallbackWatcher 
-> (FilePath -> IO ())

An IO action on the new path

-> IO CallbackId 

Add a callback that is executed when file creation is detected

Removing callbacks

unregisterCallback :: CallbackWatcher -> CallbackId -> IO () Source

Unregister the given CallbackId from the FileWatcher does nothing if the CallbackId is not in the watcher

removeAllCallbacks :: CallbackWatcher -> IO () Source

Remove all callbacks form the watcher. They will not be called after this

closeCallbackWatcher :: CallbackWatcher -> IO () Source

Remove all callbacks and close the underlying FileWatcher