Merge branch 'master' into tor

This commit is contained in:
Joey Hess 2016-11-17 12:56:27 -04:00
commit 95916b2ecf
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
149 changed files with 925 additions and 305 deletions

View file

@ -111,7 +111,7 @@ lockPidFile pidfile = do
#endif
alreadyRunning :: IO ()
alreadyRunning = error "Daemon is already running."
alreadyRunning = giveup "Daemon is already running."
{- Checks if the daemon is running, by checking that the pid file
- is locked by the same process that is listed in the pid file.
@ -135,7 +135,7 @@ checkDaemon pidfile = bracket setup cleanup go
check _ Nothing = Nothing
check (Just (pid, _)) (Just pid')
| pid == pid' = Just pid
| otherwise = error $
| otherwise = giveup $
"stale pid in " ++ pidfile ++
" (got " ++ show pid' ++
"; expected " ++ show pid ++ " )"

View file

@ -17,7 +17,7 @@ import Data.Bits ((.&.))
watchDir :: FilePath -> (FilePath -> Bool) -> Bool -> WatchHooks -> IO EventStream
watchDir dir ignored scanevents hooks = do
unlessM fileLevelEventsSupported $
error "Need at least OSX 10.7.0 for file-level FSEvents"
giveup "Need at least OSX 10.7.0 for file-level FSEvents"
scan dir
eventStreamCreate [dir] 1.0 True True True dispatch
where

View file

@ -152,7 +152,7 @@ watchDir i dir ignored scanevents hooks
-- disk full error.
| isFullError e =
case errHook hooks of
Nothing -> error $ "failed to add inotify watch on directory " ++ dir ++ " (" ++ show e ++ ")"
Nothing -> giveup $ "failed to add inotify watch on directory " ++ dir ++ " (" ++ show e ++ ")"
Just hook -> tooManyWatches hook dir
-- The directory could have been deleted.
| isDoesNotExistError e = return ()

View file

@ -1,6 +1,6 @@
{- Simple IO exception handling (and some more)
-
- Copyright 2011-2015 Joey Hess <id@joeyh.name>
- Copyright 2011-2016 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
@ -10,6 +10,7 @@
module Utility.Exception (
module X,
giveup,
catchBoolIO,
catchMaybeIO,
catchDefaultIO,
@ -40,6 +41,21 @@ import GHC.IO.Exception (IOErrorType(..))
import Utility.Data
{- Like error, this throws an exception. Unlike error, if this exception
- is not caught, it won't generate a backtrace. So use this for situations
- where there's a problem that the user is excpected to see in some
- circumstances. -}
giveup :: [Char] -> a
#ifdef MIN_VERSION_base
#if MIN_VERSION_base(4,9,0)
giveup = errorWithoutStackTrace
#else
giveup = error
#endif
#else
giveup = error
#endif
{- Catches IO errors and returns a Bool -}
catchBoolIO :: MonadCatch m => m Bool -> m Bool
catchBoolIO = catchDefaultIO False

View file

@ -12,6 +12,8 @@ module Utility.Glob (
matchGlob
) where
import Utility.Exception
import System.Path.WildMatch
import "regex-tdfa" Text.Regex.TDFA
@ -26,7 +28,7 @@ compileGlob :: String -> GlobCase -> Glob
compileGlob glob globcase = Glob $
case compile (defaultCompOpt {caseSensitive = casesentitive}) defaultExecOpt regex of
Right r -> r
Left _ -> error $ "failed to compile regex: " ++ regex
Left _ -> giveup $ "failed to compile regex: " ++ regex
where
regex = '^':wildToRegex glob
casesentitive = case globcase of

View file

@ -253,7 +253,7 @@ genRandom cmd highQuality size = checksize <$> readStrict cmd params
then s
else shortread len
shortread got = error $ unwords
shortread got = giveup $ unwords
[ "Not enough bytes returned from gpg", show params
, "(got", show got, "; expected", show expectedlength, ")"
]

View file

@ -210,7 +210,7 @@ waitLock (Seconds timeout) lockfile = go timeout
=<< tryLock lockfile
| otherwise = do
hPutStrLn stderr $ show timeout ++ " second timeout exceeded while waiting for pid lock file " ++ lockfile
error $ "Gave up waiting for possibly stale pid lock file " ++ lockfile
giveup $ "Gave up waiting for possibly stale pid lock file " ++ lockfile
dropLock :: LockHandle -> IO ()
dropLock (LockHandle lockfile _ sidelock) = do

View file

@ -79,8 +79,8 @@ forceQuery :: Query (Maybe Page)
forceQuery v ps url = query' v ps url `catchNonAsync` onerr
where
onerr e = ifM (inPath "quvi")
( error ("quvi failed: " ++ show e)
, error "quvi is not installed"
( giveup ("quvi failed: " ++ show e)
, giveup "quvi is not installed"
)
{- Returns Nothing if the page is not a video page, or quvi is not

View file

@ -16,6 +16,7 @@ module Utility.UserInfo (
import Utility.Env
import Utility.Data
import Utility.Exception
import System.PosixCompat
import Control.Applicative
@ -25,7 +26,7 @@ import Prelude
-
- getpwent will fail on LDAP or NIS, so use HOME if set. -}
myHomeDir :: IO FilePath
myHomeDir = either error return =<< myVal env homeDirectory
myHomeDir = either giveup return =<< myVal env homeDirectory
where
#ifndef mingw32_HOST_OS
env = ["HOME"]