improve programPath
Fixes a failure mode where git-annex sync would try to run git-annex and complain that it failed to find it in ~/.config/git-annex/program or PATH, when there was a git-annex in /usr/bin/, but the original one was run from elsewhere (eg, ~/bin) and happened not to be present any longer. Now, it will fall back to using git-annex from PATH in such a case. Which might fail due to some version incompatability, but still better than a misleading error message. Also made readProgramFile only read the file, not look for git-annex in PATH as a fallback. That fallback may have confused Assistant.Upgrade, which really wants the value from the file.
This commit is contained in:
parent
957a87b437
commit
a7840c0e04
2 changed files with 20 additions and 29 deletions
|
@ -32,24 +32,14 @@ programPath = go =<< getEnv "GIT_ANNEX_PROGRAMPATH"
|
|||
exe <- getExecutablePath
|
||||
p <- if isAbsolute exe
|
||||
then return exe
|
||||
else readProgramFile
|
||||
else fromMaybe exe <$> readProgramFile
|
||||
maybe cannotFindProgram return =<< searchPath p
|
||||
|
||||
{- Returns the path for git-annex that is recorded in the programFile. -}
|
||||
readProgramFile :: IO FilePath
|
||||
readProgramFile :: IO (Maybe FilePath)
|
||||
readProgramFile = do
|
||||
programfile <- programFile
|
||||
p <- catchDefaultIO cmd $
|
||||
fromMaybe cmd . headMaybe . lines <$> readFile programfile
|
||||
ifM (inPath p)
|
||||
( return p
|
||||
, ifM (inPath cmd)
|
||||
( return cmd
|
||||
, cannotFindProgram
|
||||
)
|
||||
)
|
||||
where
|
||||
cmd = "git-annex"
|
||||
headMaybe . lines <$> readFile programfile
|
||||
|
||||
cannotFindProgram :: IO a
|
||||
cannotFindProgram = do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue