make programPath return FilePath not Maybe FilePath

Looking at the few current callers, it's ok to have programPath throw an
exception, in the unusual case where it cannot find git-annex.
This commit is contained in:
Joey Hess 2015-02-28 16:59:52 -04:00
parent ad1f4a7f1c
commit b9275b65f9
4 changed files with 17 additions and 20 deletions

View file

@ -17,9 +17,10 @@ import System.Environment
- -
- getExecutablePath is available since ghc 7.4.2. On OSs it supports - getExecutablePath is available since ghc 7.4.2. On OSs it supports
- well, it returns the complete path to the program. But, on other OSs, - well, it returns the complete path to the program. But, on other OSs,
- it might return just the basename. - it might return just the basename. Fall back to reading the programFile,
- or searching for the command name in PATH.
-} -}
programPath :: IO (Maybe FilePath) programPath :: IO FilePath
programPath = do programPath = do
#if MIN_VERSION_base(4,6,0) #if MIN_VERSION_base(4,6,0)
exe <- getExecutablePath exe <- getExecutablePath
@ -29,6 +30,4 @@ programPath = do
#else #else
p <- readProgramFile p <- readProgramFile
#endif #endif
-- In case readProgramFile returned just the command name, maybe cannotFindProgram return =<< searchPath p
-- fall back to finding it in PATH.
searchPath p

View file

@ -36,8 +36,7 @@ upgradeWatcherThread urlrenderer = namedThread "UpgradeWatcher" $ do
showSuccessfulUpgrade urlrenderer showSuccessfulUpgrade urlrenderer
go =<< liftIO upgradeFlagFile go =<< liftIO upgradeFlagFile
where where
go Nothing = debug [ "cannot determine program path" ] go flagfile = do
go (Just flagfile) = do
mvar <- liftIO $ newMVar InStartupScan mvar <- liftIO $ newMVar InStartupScan
changed <- Just <$> asIO2 (changedFile urlrenderer mvar flagfile) changed <- Just <$> asIO2 (changedFile urlrenderer mvar flagfile)
let hooks = mkWatchHooks let hooks = mkWatchHooks

View file

@ -288,11 +288,8 @@ removeEmptyRecursive dir = do
{- This is a file that the UpgradeWatcher can watch for modifications to {- This is a file that the UpgradeWatcher can watch for modifications to
- detect when git-annex has been upgraded. - detect when git-annex has been upgraded.
-} -}
upgradeFlagFile :: IO (Maybe FilePath) upgradeFlagFile :: IO FilePath
upgradeFlagFile = ifM usingDistribution upgradeFlagFile = programPath
( Just <$> programFile
, programPath
)
{- Sanity check to see if an upgrade is complete and the program is ready {- Sanity check to see if an upgrade is complete and the program is ready
- to be run. -} - to be run. -}
@ -303,13 +300,10 @@ upgradeSanityCheck = ifM usingDistribution
-- Ensure that the program is present, and has no writers, -- Ensure that the program is present, and has no writers,
-- and can be run. This should handle distribution -- and can be run. This should handle distribution
-- upgrades, manual upgrades, etc. -- upgrades, manual upgrades, etc.
v <- programPath program <- programPath
case v of untilM (doesFileExist program <&&> nowriter program) $
Nothing -> return False threadDelaySeconds (Seconds 60)
Just program -> do boolSystem program [Param "version"]
untilM (doesFileExist program <&&> nowriter program) $
threadDelaySeconds (Seconds 60)
boolSystem program [Param "version"]
) )
where where
nowriter f = null nowriter f = null

View file

@ -62,8 +62,13 @@ readProgramFile = do
( return p ( return p
, ifM (inPath cmd) , ifM (inPath cmd)
( return cmd ( return cmd
, error $ "cannot find git-annex program in PATH or in the location listed in " ++ programfile , cannotFindProgram
) )
) )
where where
cmd = "git-annex" cmd = "git-annex"
cannotFindProgram :: IO a
cannotFindProgram = do
f <- programFile
error $ "cannot find git-annex program in PATH or in the location listed in " ++ f