diff --git a/Annex/Path.hs b/Annex/Path.hs index 6186a887b1..ac4e776456 100644 --- a/Annex/Path.hs +++ b/Annex/Path.hs @@ -17,9 +17,10 @@ import System.Environment - - 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, - - 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 #if MIN_VERSION_base(4,6,0) exe <- getExecutablePath @@ -29,6 +30,4 @@ programPath = do #else p <- readProgramFile #endif - -- In case readProgramFile returned just the command name, - -- fall back to finding it in PATH. - searchPath p + maybe cannotFindProgram return =<< searchPath p diff --git a/Assistant/Threads/UpgradeWatcher.hs b/Assistant/Threads/UpgradeWatcher.hs index e779c8e54d..952db1f130 100644 --- a/Assistant/Threads/UpgradeWatcher.hs +++ b/Assistant/Threads/UpgradeWatcher.hs @@ -36,8 +36,7 @@ upgradeWatcherThread urlrenderer = namedThread "UpgradeWatcher" $ do showSuccessfulUpgrade urlrenderer go =<< liftIO upgradeFlagFile where - go Nothing = debug [ "cannot determine program path" ] - go (Just flagfile) = do + go flagfile = do mvar <- liftIO $ newMVar InStartupScan changed <- Just <$> asIO2 (changedFile urlrenderer mvar flagfile) let hooks = mkWatchHooks diff --git a/Assistant/Upgrade.hs b/Assistant/Upgrade.hs index 35d63d27ae..3860a61e41 100644 --- a/Assistant/Upgrade.hs +++ b/Assistant/Upgrade.hs @@ -288,11 +288,8 @@ removeEmptyRecursive dir = do {- This is a file that the UpgradeWatcher can watch for modifications to - detect when git-annex has been upgraded. -} -upgradeFlagFile :: IO (Maybe FilePath) -upgradeFlagFile = ifM usingDistribution - ( Just <$> programFile - , programPath - ) +upgradeFlagFile :: IO FilePath +upgradeFlagFile = programPath {- Sanity check to see if an upgrade is complete and the program is ready - to be run. -} @@ -303,13 +300,10 @@ upgradeSanityCheck = ifM usingDistribution -- Ensure that the program is present, and has no writers, -- and can be run. This should handle distribution -- upgrades, manual upgrades, etc. - v <- programPath - case v of - Nothing -> return False - Just program -> do - untilM (doesFileExist program <&&> nowriter program) $ - threadDelaySeconds (Seconds 60) - boolSystem program [Param "version"] + program <- programPath + untilM (doesFileExist program <&&> nowriter program) $ + threadDelaySeconds (Seconds 60) + boolSystem program [Param "version"] ) where nowriter f = null diff --git a/Config/Files.hs b/Config/Files.hs index b503a54432..d2b2f6a514 100644 --- a/Config/Files.hs +++ b/Config/Files.hs @@ -62,8 +62,13 @@ readProgramFile = do ( return p , ifM (inPath cmd) ( return cmd - , error $ "cannot find git-annex program in PATH or in the location listed in " ++ programfile + , cannotFindProgram ) ) where 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