Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
repoquery now uses "dnf repoquery" too if available
- new repoquery function
  • Loading branch information
juhp committed Feb 15, 2015
1 parent bd3d52d commit 5b794be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/Commands/Depends.hs
Expand Up @@ -20,7 +20,7 @@ module Commands.Depends (
import Dependencies (dependencies, missingPackages, packageDependencies)
import PackageUtils (PackageData (..), prepare, stripPkgDevel)
import Setup (quiet)
import SysCmd (cmd, (+-+))
import SysCmd (repoquery, (+-+))

import Control.Applicative ((<$>))
import Control.Monad (filterM, unless, void)
Expand Down Expand Up @@ -61,7 +61,7 @@ recurseMissing already (dep:deps) = do
return $ nub $ accum2 ++ more

notAvail :: String -> IO Bool
notAvail pkg = null <$> cmd "repoquery" [pkg]
notAvail pkg = null <$> repoquery [] pkg

missingDepsPkg :: String -> IO [String]
missingDepsPkg pkg = do
Expand Down
25 changes: 11 additions & 14 deletions src/Dependencies.hs
Expand Up @@ -23,7 +23,7 @@ module Dependencies (
) where

import PackageUtils (packageName)
import SysCmd (cmd, cmdBool, optionalProgram, (+-+))
import SysCmd (cmd, cmdBool, repoquery, (+-+))

import Control.Applicative ((<$>))
import Control.Monad (filterM, liftM)
Expand Down Expand Up @@ -67,28 +67,25 @@ dependencies pkgDesc = do
clibs = concatMap extraLibs buildinfo
return (deps, tools, nub clibs, pkgcfgs, selfdep)

data RepoQueryType = Rpm | Repoquery deriving Eq

resolveLib :: String -> IO (Maybe String)
resolveLib lib = do
lib64 <- doesDirectoryExist "/usr/lib64"
let libsuffix = if lib64 then "64" else ""
let lib_path = "/usr/lib" ++ libsuffix ++ "/lib" ++ lib ++ ".so"
libInst <- doesFileExist lib_path
if libInst
then rpmqueryFile "rpm" lib_path
then rpmqueryFile Rpm lib_path
else do
haveRpqry <- optionalProgram "repoquery"
if haveRpqry
then do
putStrLn $ "Running repoquery on" +-+ "lib" ++ lib
rpmqueryFile "repoquery" lib_path
else do
warning $ "Install yum-utils to resolve package that provides uninstalled" +-+ lib_path
return Nothing
putStrLn $ "Running repoquery on" +-+ "lib" ++ lib
rpmqueryFile Repoquery lib_path

-- use repoquery or rpm -q to query which package provides file
rpmqueryFile :: String -> FilePath -> IO (Maybe String)
rpmqueryFile qc file = do
out <- cmd qc ["-q", "--qf=%{name}", "-f", file]
rpmqueryFile :: RepoQueryType -> FilePath -> IO (Maybe String)
rpmqueryFile qt file = do
let args = ["-q", "--qf=%{name}", "-f"]
out <- (if qt == Rpm then cmd "rpm" (args ++ [file]) else repoquery args file)
let pkgs = nub $ words out
-- EL5 repoquery can return "No package provides <file>"
case pkgs of
Expand Down Expand Up @@ -141,7 +138,7 @@ notInstalled dep =

derefPkg :: String -> IO String
derefPkg req = do
res <- singleLine <$> cmd "repoquery" ["--qf", "%{name}", "--whatprovides", req]
res <- singleLine <$> repoquery ["--qf", "%{name}", "--whatprovides"] req
if null res
then error $ req +-+ "provider not found by repoquery"
else return res
Expand Down
12 changes: 9 additions & 3 deletions src/SysCmd.hs
Expand Up @@ -23,6 +23,7 @@ module SysCmd (
cmdQuiet,
cmdSilent,
pkgInstall,
repoquery,
rpmInstall,
trySystem,
shell,
Expand All @@ -32,7 +33,7 @@ module SysCmd (
import Control.Monad (unless, void, when)
import Data.Functor ((<$>))
import Data.List ((\\))
import Data.Maybe (fromMaybe, isJust, isNothing)
import Data.Maybe (fromMaybe, isJust, isNothing, maybeToList)

import Distribution.Simple.Utils (die, warn, findProgramLocation)
import Distribution.Verbosity (normal)
Expand Down Expand Up @@ -128,13 +129,18 @@ packageManager = do
then return "dnf"
else requireProgram "yum" >> return "yum"

repoquery :: [String] -> String -> IO String
repoquery args key = do
havednf <- optionalProgram "dnf"
let (prog, subcmd) = if havednf then ("dnf", Just "repoquery") else ("repoquery", Nothing)
cmd prog (maybeToList subcmd ++ args ++ [key])

pkgInstall :: [String] -> Bool -> IO ()
pkgInstall [] _ = return ()
pkgInstall pkgs hard = do
pkginstaller <- packageManager
putStrLn $ "Running repoquery" +-+ unwords pkgs
let (repoquery, arg) = if pkginstaller == "dnf" then ("dnf", ["repoquery"]) else ("repoquery", [])
repopkgs <- lines <$> readProcess repoquery (arg ++ ["--qf", "%{name}"] ++ pkgs) []
repopkgs <- mapM (repoquery ["--qf", "%{name}"]) pkgs
let missing = pkgs \\ repopkgs
if not (null missing) && hard
then error $ unwords missing +-+ "not available."
Expand Down

0 comments on commit 5b794be

Please sign in to comment.