use programPath consistently, not readProgramFile

Improve git-annex's ability to find the path to its program, especially
when it needs to run itself in another repo to upgrade it.

Some parts of the code used readProgramFile, probably because I forgot that
programPath exists.

I noticed this when a git-annex auto-upgrade failed because it was running
git-annex upgrade --autoonly, but the code to run git-annex used
readProgramFile, which happened to point to an older build of git-annex.
This commit is contained in:
Joey Hess 2020-03-30 16:03:44 -04:00
parent f83ead0240
commit 87d5583a91
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
8 changed files with 38 additions and 31 deletions

View file

@ -7,7 +7,7 @@
module Annex.Multicast where module Annex.Multicast where
import Config.Files import Annex.Path
import Utility.Env import Utility.Env
import Utility.PartialPrelude import Utility.PartialPrelude
@ -22,7 +22,7 @@ multicastReceiveEnv = "GIT_ANNEX_MULTICAST_RECEIVE"
multicastCallbackEnv :: IO (FilePath, [(String, String)], Handle) multicastCallbackEnv :: IO (FilePath, [(String, String)], Handle)
multicastCallbackEnv = do multicastCallbackEnv = do
gitannex <- readProgramFile gitannex <- programPath
-- This will even work on Windows -- This will even work on Windows
(rfd, wfd) <- createPipeFd (rfd, wfd) <- createPipeFd
rh <- fdToHandle rfd rh <- fdToHandle rfd

View file

@ -34,3 +34,24 @@ programPath = go =<< getEnv "GIT_ANNEX_PROGRAMPATH"
then return exe then return exe
else readProgramFile else readProgramFile
maybe cannotFindProgram return =<< searchPath p maybe cannotFindProgram return =<< searchPath p
{- Returns the path for git-annex that is recorded in the programFile. -}
readProgramFile :: IO 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"
cannotFindProgram :: IO a
cannotFindProgram = do
f <- programFile
giveup $ "cannot find git-annex program in PATH or in " ++ f

View file

@ -33,7 +33,7 @@ import Assistant.WebApp.SideBar
import Command.P2P (unusedPeerRemoteName, PairingResult(..)) import Command.P2P (unusedPeerRemoteName, PairingResult(..))
import P2P.Address import P2P.Address
import Git import Git
import Config.Files import Annex.Path
import Utility.Process.Transcript import Utility.Process.Transcript
import qualified Data.Map as M import qualified Data.Map as M
@ -72,7 +72,7 @@ getPrepareWormholePairR pairingwith = do
enableTor :: Handler () enableTor :: Handler ()
enableTor = do enableTor = do
gitannex <- liftIO readProgramFile gitannex <- liftIO programPath
(transcript, ok) <- liftIO $ processTranscript gitannex ["enable-tor"] Nothing (transcript, ok) <- liftIO $ processTranscript gitannex ["enable-tor"] Nothing
if ok if ok
-- Reload remotedameon so it's serving the tor hidden -- Reload remotedameon so it's serving the tor hidden

View file

@ -1,3 +1,10 @@
git-annex (8.20200331) UNRELEASED; urgency=medium
* Improve git-annex's ability to find the path to its program,
especially when it needs to run itself in another repo to upgrade it.
-- Joey Hess <id@joeyh.name> Mon, 30 Mar 2020 15:58:34 -0400
git-annex (8.20200330) upstream; urgency=medium git-annex (8.20200330) upstream; urgency=medium
* fsck: Fix reversion in 8.20200226 that made it incorrectly warn * fsck: Fix reversion in 8.20200226 that made it incorrectly warn

View file

@ -16,7 +16,7 @@ import P2P.Annex
import Utility.Tor import Utility.Tor
import Annex.UUID import Annex.UUID
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
import Config.Files import Annex.Path
#endif #endif
import P2P.IO import P2P.IO
import qualified P2P.Protocol as P2P import qualified P2P.Protocol as P2P
@ -53,7 +53,7 @@ start _os = do
Nothing -> giveup "Need user-id parameter." Nothing -> giveup "Need user-id parameter."
Just userid -> go userid Just userid -> go userid
else starting "enable-tor" (ActionItemOther Nothing) $ do else starting "enable-tor" (ActionItemOther Nothing) $ do
gitannex <- liftIO readProgramFile gitannex <- liftIO programPath
let ps = [Param (cmdname cmd), Param (show curruserid)] let ps = [Param (cmdname cmd), Param (show curruserid)]
sucommand <- liftIO $ mkSuCommand gitannex ps sucommand <- liftIO $ mkSuCommand gitannex ps
maybe noop showLongNote maybe noop showLongNote

View file

@ -46,7 +46,7 @@ import Config
import Config.GitConfig import Config.GitConfig
import Annex.SpecialRemote.Config import Annex.SpecialRemote.Config
import Config.DynamicConfig import Config.DynamicConfig
import Config.Files import Annex.Path
import Annex.Wanted import Annex.Wanted
import Annex.Content import Annex.Content
import Command.Get (getKey') import Command.Get (getKey')
@ -509,7 +509,7 @@ pushRemote o remote (Just branch, _) = do
Nothing -> return True Nothing -> return True
Just wt -> ifM needemulation Just wt -> ifM needemulation
( liftIO $ do ( liftIO $ do
p <- readProgramFile p <- programPath
boolSystem' p [Param "post-receive"] boolSystem' p [Param "post-receive"]
(\cp -> cp { cwd = Just (fromRawFilePath wt) }) (\cp -> cp { cwd = Just (fromRawFilePath wt) })
, return True , return True

View file

@ -61,27 +61,6 @@ removeAutoStartFile path = do
programFile :: IO FilePath programFile :: IO FilePath
programFile = userConfigFile "program" programFile = userConfigFile "program"
{- Returns a command to run for git-annex. -}
readProgramFile :: IO 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"
cannotFindProgram :: IO a
cannotFindProgram = do
f <- programFile
giveup $ "cannot find git-annex program in PATH or in the location listed in " ++ f
{- A .noannex file in a git repository prevents git-annex from {- A .noannex file in a git repository prevents git-annex from
- initializing that repository.. The content of the file is returned. -} - initializing that repository.. The content of the file is returned. -}
noAnnexFileContent :: Maybe FilePath -> IO (Maybe String) noAnnexFileContent :: Maybe FilePath -> IO (Maybe String)

View file

@ -13,7 +13,7 @@ import Annex.Common
import qualified Annex import qualified Annex
import qualified Git import qualified Git
import Config import Config
import Config.Files import Annex.Path
import Annex.Version import Annex.Version
import Types.RepoVersion import Types.RepoVersion
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
@ -103,7 +103,7 @@ upgrade automatic destversion = do
-- upgrading a git repo other than the current repo. -- upgrading a git repo other than the current repo.
upgraderemote = do upgraderemote = do
rp <- fromRawFilePath <$> fromRepo Git.repoPath rp <- fromRawFilePath <$> fromRepo Git.repoPath
cmd <- liftIO readProgramFile cmd <- liftIO programPath
liftIO $ boolSystem' cmd liftIO $ boolSystem' cmd
[ Param "upgrade" [ Param "upgrade"
, Param "--quiet" , Param "--quiet"