2013-11-24 20:03:03 +00:00
|
|
|
{- git-annex program path
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2013 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
|
|
|
|
|
|
|
|
import Common
|
|
|
|
import Config.Files
|
2015-03-27 16:55:18 +00:00
|
|
|
import Utility.Env
|
|
|
|
|
|
|
|
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
|