summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-04-21 23:32:33 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-04-21 23:32:33 -0400
commited79596b758935a3f22bf6803bc082a6bbe10f58 (patch)
tree885a8a50e68dafb39ec886cb31aa4c549fbeb35e /Utility
parentbee420bd2d0cbe16489b061b208083e2b8ba9d0e (diff)
noop
Diffstat (limited to 'Utility')
-rw-r--r--Utility/Directory.hs3
-rw-r--r--Utility/Inotify.hs10
-rw-r--r--Utility/Monad.hs4
-rw-r--r--Utility/Touch.hsc7
-rw-r--r--Utility/Url.hs3
5 files changed, 16 insertions, 11 deletions
diff --git a/Utility/Directory.hs b/Utility/Directory.hs
index 40e65d634..e6622d31e 100644
--- a/Utility/Directory.hs
+++ b/Utility/Directory.hs
@@ -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
diff --git a/Utility/Inotify.hs b/Utility/Inotify.hs
index 0a261ecfe..d41e997d6 100644
--- a/Utility/Inotify.hs
+++ b/Utility/Inotify.hs
@@ -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 ()
diff --git a/Utility/Monad.hs b/Utility/Monad.hs
index 9c85d31ca..2c9b9e9e0 100644
--- a/Utility/Monad.hs
+++ b/Utility/Monad.hs
@@ -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 ()
diff --git a/Utility/Touch.hsc b/Utility/Touch.hsc
index b53eab634..e2dba79ab 100644
--- a/Utility/Touch.hsc
+++ b/Utility/Touch.hsc
@@ -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
diff --git a/Utility/Url.hs b/Utility/Url.hs
index 86d66d83b..20c5db574 100644
--- a/Utility/Url.hs
+++ b/Utility/Url.hs
@@ -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:_) ->