Revision 6fd8ceff src/Ganeti/ConfigReader.hs

b/src/Ganeti/ConfigReader.hs
32 32

  
33 33
import Control.Concurrent
34 34
import Control.Exception
35
import Control.Monad (liftM, unless)
35
import Control.Monad (unless)
36 36
import Data.IORef
37
import System.Posix.Files
38
import System.Posix.Types
39 37
import System.INotify
40 38

  
41 39
import Ganeti.BasicTypes
......
51 49
-- executed.
52 50
type ConfigReader = IO (Result ConfigData)
53 51

  
54
-- | File stat identifier.
55
type FStat = (EpochTime, FileID, FileOffset)
56

  
57
-- | Null 'FStat' value.
58
nullFStat :: FStat
59
nullFStat = (-1, -1, -1)
60 52

  
61 53
-- | Reload model data type.
62 54
data ReloadModel = ReloadNotify      -- ^ We are using notifications
......
151 143
             return (nullFStat, ConfigIOError)
152 144
          )
153 145

  
154
-- | Computes the file cache data from a FileStatus structure.
155
buildFileStatus :: FileStatus -> FStat
156
buildFileStatus ofs =
157
    let modt = modificationTime ofs
158
        inum = fileID ofs
159
        fsize = fileSize ofs
160
    in (modt, inum, fsize)
161

  
162
-- | Wrapper over 'buildFileStatus'. This reads the data from the
163
-- filesystem and then builds our cache structure.
164
getFStat :: FilePath -> IO FStat
165
getFStat p = liftM buildFileStatus (getFileStatus p)
166

  
167
-- | Check if the file needs reloading
168
needsReload :: FStat -> FilePath -> IO (Maybe FStat)
169
needsReload oldstat path = do
170
  newstat <- getFStat path
171
  return $ if newstat /= oldstat
172
             then Just newstat
173
             else Nothing
174

  
175 146
-- ** Watcher threads
176 147

  
177 148
-- $watcher

Also available in: Unified diff