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:
Joey Hess 2020-04-15 16:46:34 -04:00
parent 957a87b437
commit a7840c0e04
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 20 additions and 29 deletions

View file

@ -32,24 +32,14 @@ programPath = go =<< getEnv "GIT_ANNEX_PROGRAMPATH"
exe <- getExecutablePath exe <- getExecutablePath
p <- if isAbsolute exe p <- if isAbsolute exe
then return exe then return exe
else readProgramFile else fromMaybe exe <$> readProgramFile
maybe cannotFindProgram return =<< searchPath p maybe cannotFindProgram return =<< searchPath p
{- Returns the path for git-annex that is recorded in the programFile. -} {- Returns the path for git-annex that is recorded in the programFile. -}
readProgramFile :: IO FilePath readProgramFile :: IO (Maybe FilePath)
readProgramFile = do readProgramFile = do
programfile <- programFile programfile <- programFile
p <- catchDefaultIO cmd $ headMaybe . lines <$> readFile programfile
fromMaybe cmd . headMaybe . lines <$> readFile programfile
ifM (inPath p)
( return p
, ifM (inPath cmd)
( return cmd
, cannotFindProgram
)
)
where
cmd = "git-annex"
cannotFindProgram :: IO a cannotFindProgram :: IO a
cannotFindProgram = do cannotFindProgram = do

View file

@ -225,8 +225,10 @@ upgradeToDistribution newdir cleanup distributionfile = do
{- Finds where the old version was installed. -} {- Finds where the old version was installed. -}
oldVersionLocation :: IO FilePath oldVersionLocation :: IO FilePath
oldVersionLocation = do oldVersionLocation = readProgramFile >>= \case
pdir <- parentDir <$> readProgramFile Nothing -> error "Cannot find old distribution bundle; not upgrading."
Just pf -> do
let pdir = parentDir pf
#ifdef darwin_HOST_OS #ifdef darwin_HOST_OS
let dirs = splitDirectories pdir let dirs = splitDirectories pdir
{- It will probably be deep inside a git-annex.app directory. -} {- It will probably be deep inside a git-annex.app directory. -}
@ -344,10 +346,9 @@ distributionInfoSigUrl = distributionInfoUrl ++ ".sig"
- trustedkeys.gpg, next to the git-annex program. - trustedkeys.gpg, next to the git-annex program.
-} -}
verifyDistributionSig :: GpgCmd -> FilePath -> IO Bool verifyDistributionSig :: GpgCmd -> FilePath -> IO Bool
verifyDistributionSig gpgcmd sig = do verifyDistributionSig gpgcmd sig = readProgramFile >>= \case
p <- readProgramFile Just p | isAbsolute p ->
if isAbsolute p withUmask 0o0077 $ withTmpDir "git-annex-gpg.tmp" $ \gpgtmp -> do
then withUmask 0o0077 $ withTmpDir "git-annex-gpg.tmp" $ \gpgtmp -> do
let trustedkeys = takeDirectory p </> "trustedkeys.gpg" let trustedkeys = takeDirectory p </> "trustedkeys.gpg"
boolGpgCmd gpgcmd boolGpgCmd gpgcmd
[ Param "--no-default-keyring" [ Param "--no-default-keyring"
@ -360,4 +361,4 @@ verifyDistributionSig gpgcmd sig = do
, Param "--verify" , Param "--verify"
, File sig , File sig
] ]
else return False _ -> return False