This commit is contained in:
Joey Hess 2012-04-21 23:32:33 -04:00
parent bee420bd2d
commit ed79596b75
27 changed files with 56 additions and 52 deletions

View file

@ -19,6 +19,7 @@ import Control.Applicative
import Utility.SafeCommand
import Utility.TempFile
import Utility.Exception
import Utility.Monad
{- Lists the contents of a directory.
- Unlike getDirectoryContents, paths are not relative to the directory. -}
@ -34,7 +35,7 @@ dirContents d = map (d </>) . filter notcruft <$> getDirectoryContents d
moveFile :: FilePath -> FilePath -> IO ()
moveFile src dest = tryIO (rename src dest) >>= onrename
where
onrename (Right _) = return ()
onrename (Right _) = noop
onrename (Left e)
| isPermissionError e = rethrow
| isDoesNotExistError e = rethrow

View file

@ -56,7 +56,7 @@ watchDir' scan i test add del dir = do
then void $ do
_ <- addWatch i watchevents dir go
mapM walk =<< dirContents dir
else return ()
else noop
where
watchevents
| isJust add && isJust del =
@ -68,19 +68,19 @@ watchDir' scan i test add del dir = do
recurse = watchDir' scan i test add del
walk f = ifM (catchBoolIO $ Files.isDirectory <$> getFileStatus f)
( recurse f
, if scan && isJust add then fromJust add f else return ()
, when (scan && isJust add) $ fromJust add f
)
go (Created { isDirectory = False }) = return ()
go (Created { isDirectory = False }) = noop
go (Created { filePath = subdir }) = Just recurse <@> subdir
go (Closed { maybeFilePath = Just f }) = add <@> f
go (MovedIn { isDirectory = False, filePath = f }) = add <@> f
go (MovedOut { isDirectory = False, filePath = f }) = del <@> f
go (Deleted { isDirectory = False, filePath = f }) = del <@> f
go _ = return ()
go _ = noop
Just a <@> f = a $ dir </> f
Nothing <@> _ = return ()
Nothing <@> _ = noop
{- Pauses the main thread, letting children run until program termination. -}
waitForTermination :: IO ()

View file

@ -49,3 +49,7 @@ observe observer a = do
{- b `after` a runs first a, then b, and returns the value of a -}
after :: Monad m => m b -> m a -> m a
after = observe . const
{- do nothing -}
noop :: Monad m => m ()
noop = return ()

View file

@ -106,9 +106,8 @@ touchBoth file atime mtime follow =
withFilePath file $ \f -> do
pokeArray ptr [atime, mtime]
r <- syscall f ptr
if (r /= 0)
then throwErrno "touchBoth"
else return ()
when (r /= 0) $
throwErrno "touchBoth"
where
syscall = if follow
then c_lutimes
@ -116,6 +115,6 @@ touchBoth file atime mtime follow =
#else
#warning "utimensat and lutimes not available; building without symlink timestamp preservation support"
touchBoth _ _ _ _ = return ()
touchBoth _ _ _ _ = noop
#endif
#endif

View file

@ -17,6 +17,7 @@ import Common
import qualified Network.Browser as Browser
import Network.HTTP
import Network.URI
import Utility.Monad
type URLString = String
@ -95,7 +96,7 @@ request url requesttype = go 5 url
case rspCode rsp of
(3,0,x) | x /= 5 -> redir (n - 1) u rsp
_ -> return rsp
ignore = const $ return ()
ignore = const noop
redir n u rsp = case retrieveHeaders HdrLocation rsp of
[] -> return rsp
(Header _ newu:_) ->