LGTM, thanks
On Fri, Dec 20, 2013 at 2:41 PM, Klaus Aehlig <[email protected]> wrote: > When watching a file, reinstantiate the inotify if notified > of an event that removes the watch. Such events are likely > to happen, as our usual way to "modify" a file is to atomically > replace it by another one. > > Signed-off-by: Klaus Aehlig <[email protected]> > --- > src/Ganeti/Utils.hs | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > diff --git a/src/Ganeti/Utils.hs b/src/Ganeti/Utils.hs > index bdd677b..ebd93a4 100644 > --- a/src/Ganeti/Utils.hs > +++ b/src/Ganeti/Utils.hs > @@ -75,12 +75,12 @@ module Ganeti.Utils > > import Control.Concurrent > import Control.Exception (try) > +import Control.Monad (foldM, liftM, when) > import Data.Char (toUpper, isAlphaNum, isDigit, isSpace) > import Data.Function (on) > import Data.IORef > import Data.List > import qualified Data.Map as M > -import Control.Monad (foldM, liftM) > import System.Directory (renameFile) > import System.FilePath.Posix (takeDirectory, takeBaseName) > import System.INotify > @@ -618,11 +618,15 @@ watchFile fpath timeout old read_fn = do > fstat <- getFStatSafe fpath > ref <- newIORef fstat > inotify <- initINotify > - _ <- addWatch inotify [Modify, Delete] fpath $ \ e -> do > - logDebug $ "Notified of change in " ++ fpath > - ++ "; event: " ++ show e > - fstat' <- getFStatSafe fpath > - writeIORef ref fstat' > + let do_watch e = do > + logDebug $ "Notified of change in " ++ fpath > + ++ "; event: " ++ show e > + when (e == Ignored) > + (addWatch inotify [Modify, Delete] fpath do_watch > + >> return ()) > + fstat' <- getFStatSafe fpath > + writeIORef ref fstat' > + _ <- addWatch inotify [Modify, Delete] fpath do_watch > newval <- read_fn > if newval /= old > then do > -- > 1.8.5.1 > > -- -- Helga Velroyen | Software Engineer | [email protected] | Google Germany GmbH Dienerstr. 12 80331 München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores
