delta-0.1.2.0: 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).

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

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 PollWatcher

Build a file watcher, this method will change later

deltaDirWithCallbacks :: FilePath -> IO (CallbackWatcher PollWatcher)

Build a file watcher that allows to register callbacks

FRP based interface

class FileWatcher a where

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

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

Methods

defaultWatcher :: FilePath -> IO a

Each type provides a default watcher for a pass

changedFiles :: a -> Event FileInfo

An event that gives some info on changed files (disjunct from deleted and new files)

newFiles :: a -> Event FilePath

An event that fires for each new file

deletedFiles :: a -> Event FilePath

An event that fires for each deleted path

cleanUpAndClose :: a -> IO ()

Free all possibly used resources. No event will fire after this.

mergeWatchers :: a -> a -> a

Merge two watchers that are watching different directories

watchPaths :: FileWatcher a => [FilePath] -> Maybe (IO a)

Create a watcher on all of the given paths

Callback based interface

data CallbackWatcher w

Provides a callback based interface to an FRP base FileWatcher

data CallbackId

Id of a callback in a CallbackWatcher

withCallbacks :: FileWatcher a => a -> IO (CallbackWatcher a)

Wrap a file watcher in a datatype that allows adding callbacks

Adding callbacks

withDeleteCallback

Arguments

:: FileWatcher a 
=> CallbackWatcher a 
-> (FilePath -> IO ())

An IO action on the deleted path

-> IO CallbackId 

Add a callback that is executed when file deletion is detected

withChangedCallback

Arguments

:: FileWatcher a 
=> CallbackWatcher a 
-> (FileInfo -> IO ())

Action on changed file

-> IO CallbackId 

Add a callback on a changed file

withNewCallback

Arguments

:: FileWatcher a 
=> CallbackWatcher a 
-> (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 :: FileWatcher a => CallbackWatcher a -> CallbackId -> IO ()

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

removeAllCallbacks :: FileWatcher a => CallbackWatcher a -> IO ()

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

closeCallbackWatcher :: FileWatcher a => CallbackWatcher a -> IO ()

Remove all callbacks and close the underlying FileWatcher