module XMonad.Util.EntryHelper.File
( XMonadPaths(..)
, getXMonadDir
, getXMonadPaths
, getXMonadBin
, getXMonadLog
, getXMonadSrc
, getXMonadLibDir
, isSourceNewer
) where
import Control.Applicative
import System.FilePath
import qualified XMonad.Core as XC
import System.Info
import System.Directory
import XMonad.Util.EntryHelper.Util
data XMonadPaths = XMonadPaths
{ dirPath :: FilePath
, binPath :: FilePath
, logPath :: FilePath
, srcPath :: FilePath
, libDirPath :: FilePath
} deriving (Show)
getXMonadPaths :: IO XMonadPaths
getXMonadPaths = (XMonadPaths
<$> id
<*> (</> "xmonad-"++arch++"-"++os)
<*> (</> "xmonad.errors")
<*> (</> "xmonad.hs")
<*> (</> "lib")) <$> getXMonadDir
getXMonadBin, getXMonadLog, getXMonadSrc, getXMonadLibDir, getXMonadDir :: IO FilePath
getXMonadDir = XC.getXMonadDir
getXMonadBin = binPath <$> getXMonadPaths
getXMonadLog = logPath <$> getXMonadPaths
getXMonadSrc = srcPath <$> getXMonadPaths
getXMonadLibDir = libDirPath <$> getXMonadPaths
isSourceNewer :: IO Bool
isSourceNewer = do
paths <- getXMonadPaths
let bin = binPath paths
src = srcPath paths
lib = libDirPath paths
libTs <- mapM getModTime . filter isHaskellSourceFile =<< allFiles lib
srcT <- getModTime src
binT <- getModTime bin
return $ any (binT <) (srcT : libTs)
where
getModTime = safeIO' . getModificationTime