summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-12-14 15:52:44 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-12-14 16:07:59 -0400
commit3780a5eb0a01e3d31fc0de2410f7b01518710a0e (patch)
tree0b187086ee7cb6ed6dd1c49b4dd0871c856a27cd /Utility
parentd6adaf499124c11e3d79252821ef400d2a87b155 (diff)
move thirdparty program installation for standalone bundle into haskell program
This allows it to use Build.SysConfig to always install the programs configure detected. Amoung other fixes, this ensures the right uuid generator and checksum programs are installed. I also cleaned up the handling of lsof's path; configure now checks for it in PATH, but falls back to looking for it in sbin directories.
Diffstat (limited to 'Utility')
-rw-r--r--Utility/Lsof.hs13
-rw-r--r--Utility/Path.hs20
2 files changed, 30 insertions, 3 deletions
diff --git a/Utility/Lsof.hs b/Utility/Lsof.hs
index 72f3e5815..9a877a3c9 100644
--- a/Utility/Lsof.hs
+++ b/Utility/Lsof.hs
@@ -10,8 +10,10 @@
module Utility.Lsof where
import Common
+import Build.SysConfig as SysConfig
import System.Posix.Types
+import System.Posix.Env
data LsofOpenMode = OpenReadWrite | OpenReadOnly | OpenWriteOnly | OpenUnknown
deriving (Show, Eq)
@@ -21,6 +23,17 @@ type CmdLine = String
data ProcessInfo = ProcessInfo ProcessID CmdLine
deriving (Show)
+{- lsof is not in PATH on all systems, so SysConfig may have the absolute
+ - path where the program was found. Make sure at runtime that lsof is
+ - available, and if it's not in PATH, adjust PATH to contain it. -}
+setupLsof :: IO ()
+setupLsof = do
+ let cmd = fromMaybe "lsof" SysConfig.lsof
+ when (isAbsolute cmd) $ do
+ path <- getSearchPath
+ let path' = takeDirectory cmd : path
+ setEnv "PATH" (join [searchPathSeparator] path') True
+
{- Checks each of the files in a directory to find open files.
- Note that this will find hard links to files elsewhere that are open. -}
queryDir :: FilePath -> IO [(FilePath, LsofOpenMode, ProcessInfo)]
diff --git a/Utility/Path.hs b/Utility/Path.hs
index 4bab297da..ba836d9b6 100644
--- a/Utility/Path.hs
+++ b/Utility/Path.hs
@@ -132,11 +132,25 @@ relHome path = do
then "~/" ++ relPathDirToFile home path
else path
-{- Checks if a command is available in PATH. -}
+{- Checks if a command is available in PATH.
+ -
+ - The command may be fully-qualified, in which case, this succeeds as
+ - long as it exists. -}
inPath :: String -> IO Bool
-inPath command = getSearchPath >>= anyM indir
+inPath command = isJust <$> searchPath command
+
+{- Finds a command in PATH and returns the full path to it.
+ -
+ - The command may be fully qualified already, in which case it will
+ - be returned if it exists.
+ -}
+searchPath :: String -> IO (Maybe FilePath)
+searchPath command
+ | isAbsolute command = check command
+ | otherwise = getSearchPath >>= getM indir
where
- indir d = doesFileExist $ d </> command
+ indir d = check $ d </> command
+ check f = ifM (doesFileExist f) ( return (Just f), return Nothing )
{- Checks if a filename is a unix dotfile. All files inside dotdirs
- count as dotfiles. -}