2013-11-24 20:03:03 +00:00
|
|
|
{- git-annex program path
|
|
|
|
-
|
2020-08-25 18:57:25 +00:00
|
|
|
- Copyright 2013-2020 Joey Hess <id@joeyh.name>
|
2013-11-24 20:03:03 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-11-24 20:03:03 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Annex.Path where
|
|
|
|
|
2020-08-25 18:57:25 +00:00
|
|
|
import Annex.Common
|
2013-11-24 20:03:03 +00:00
|
|
|
import Config.Files
|
2015-03-27 16:55:18 +00:00
|
|
|
import Utility.Env
|
2020-08-26 16:20:56 +00:00
|
|
|
import Annex.PidLock
|
2015-03-27 16:55:18 +00:00
|
|
|
|
|
|
|
import System.Environment (getExecutablePath)
|
2013-11-24 20:03:03 +00:00
|
|
|
|
|
|
|
{- A fully qualified path to the currently running git-annex program.
|
|
|
|
-
|
2017-12-14 17:45:50 +00:00
|
|
|
- getExecutablePath is used when possible. On OSs it supports
|
2013-11-24 20:03:03 +00:00
|
|
|
- well, it returns the complete path to the program. But, on other OSs,
|
2015-02-28 20:59:52 +00:00
|
|
|
- it might return just the basename. Fall back to reading the programFile,
|
|
|
|
- or searching for the command name in PATH.
|
2015-03-27 16:55:18 +00:00
|
|
|
-
|
|
|
|
- The standalone build runs git-annex via ld.so, and defeats
|
|
|
|
- getExecutablePath. It sets GIT_ANNEX_PROGRAMPATH to the correct path
|
|
|
|
- to the wrapper script to use.
|
2013-11-24 20:03:03 +00:00
|
|
|
-}
|
2015-02-28 20:59:52 +00:00
|
|
|
programPath :: IO FilePath
|
2015-03-27 16:55:18 +00:00
|
|
|
programPath = go =<< getEnv "GIT_ANNEX_PROGRAMPATH"
|
|
|
|
where
|
|
|
|
go (Just p) = return p
|
|
|
|
go Nothing = do
|
|
|
|
exe <- getExecutablePath
|
|
|
|
p <- if isAbsolute exe
|
|
|
|
then return exe
|
2020-04-15 20:46:34 +00:00
|
|
|
else fromMaybe exe <$> readProgramFile
|
2015-03-27 16:55:18 +00:00
|
|
|
maybe cannotFindProgram return =<< searchPath p
|
2020-03-30 20:03:44 +00:00
|
|
|
|
|
|
|
{- Returns the path for git-annex that is recorded in the programFile. -}
|
2020-04-15 20:46:34 +00:00
|
|
|
readProgramFile :: IO (Maybe FilePath)
|
2020-03-30 20:03:44 +00:00
|
|
|
readProgramFile = do
|
|
|
|
programfile <- programFile
|
2020-04-15 20:46:34 +00:00
|
|
|
headMaybe . lines <$> readFile programfile
|
2020-03-30 20:03:44 +00:00
|
|
|
|
|
|
|
cannotFindProgram :: IO a
|
|
|
|
cannotFindProgram = do
|
|
|
|
f <- programFile
|
|
|
|
giveup $ "cannot find git-annex program in PATH or in " ++ f
|
2020-08-25 18:57:25 +00:00
|
|
|
|
|
|
|
{- Runs a git-annex child process.
|
|
|
|
-
|
|
|
|
- Like runsGitAnnexChildProcessViaGit, when pid locking is in use,
|
|
|
|
- this takes the pid lock, while running it, and sets an env var
|
|
|
|
- that prevents the child process trying to take the pid lock,
|
|
|
|
- to avoid it deadlocking.
|
|
|
|
-}
|
|
|
|
gitAnnexChildProcess
|
|
|
|
:: [String]
|
|
|
|
-> (CreateProcess -> CreateProcess)
|
|
|
|
-> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> IO a)
|
|
|
|
-> Annex a
|
|
|
|
gitAnnexChildProcess ps f a = do
|
|
|
|
cmd <- liftIO programPath
|
2020-08-26 16:20:56 +00:00
|
|
|
pidLockChildProcess cmd ps f a
|