Permalink
Browse files

commandline: inhibit shell expansion of passed arguments

Consider the following command:

    $ haskell-updater --all -C echo '*'

Before the patch:
  Showed contents of current directory followed by installed package list:

    foo bar dev-haskell/syb

After the patch:
  Works as expected and renders asterisk:

    * dev-haskell/syb

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
  • Loading branch information...
1 parent 4c0ccbf commit 942eef37a7d8bc00efb93a6e847cc0353ecc820d @trofi trofi committed Feb 11, 2012
Showing with 14 additions and 12 deletions.
  1. +2 −2 Distribution/Gentoo/PkgManager.hs
  2. +12 −10 Main.hs
View
4 Distribution/Gentoo/PkgManager.hs
@@ -106,8 +106,8 @@ defaultPMFlags Paludis = [ "resolve", "--execute", "--preserve-world"
defaultPMFlags CustomPM{} = []
defaultPMFlags (InvalidPM _) = undefined
-buildCmd :: PkgManager -> [PMFlag] -> [String] -> [Package] -> String
-buildCmd pm fs raw_pm_flags ps = unwords $ pmCommand pm : fs' ++ ps'
+buildCmd :: PkgManager -> [PMFlag] -> [String] -> [Package] -> (String, [String])
+buildCmd pm fs raw_pm_flags ps = (pmCommand pm, fs' ++ ps')
where
fs' = defaultPMFlags pm ++ mapMaybe (flagRep pm) fs ++ raw_pm_flags
ps' = map printPkg ps
View
22 Main.hs
@@ -25,8 +25,8 @@ import System.Console.GetOpt
import System.Environment(getArgs, getProgName)
import System.Exit(ExitCode(..), exitWith)
import System.IO(hPutStrLn, stderr)
-import Control.Monad(liftM, liftM2, unless)
-import System.Process(system)
+import Control.Monad(liftM, unless)
+import System.Process(rawSystem)
-- -----------------------------------------------------------------------------
-- The overall program.
@@ -102,19 +102,21 @@ data WithCmd = RunOnly
| PrintAndRun
deriving (Eq, Ord, Show, Read)
-runCmd :: WithCmd -> String -> IO a
-runCmd RunOnly = runCommand
-runCmd PrintOnly = success
-runCmd PrintAndRun = liftM2 (>>) putStrLn runCommand
+runCmd :: WithCmd -> String -> [String] -> IO a
+runCmd mode cmd args = case mode of
+ RunOnly -> runCommand cmd args
+ PrintOnly -> success cmd_line
+ PrintAndRun -> putStrLn cmd_line >> runCommand cmd args
+ where cmd_line = unwords (cmd:args)
-runCommand :: String -> IO a
-runCommand cmd = system cmd >>= exitWith
+runCommand :: String -> [String] -> IO a
+runCommand cmd args = rawSystem cmd args >>= exitWith
buildPkgs :: RunModifier -> [Package] -> IO a
buildPkgs _ [] = success "\nNothing to build!"
-buildPkgs rm ps = runCmd (withCmd rm) cmd
+buildPkgs rm ps = runCmd (withCmd rm) cmd args
where
- cmd = buildCmd (pkgmgr rm) (flags rm) (rawPMArgs rm) ps
+ (cmd, args) = buildCmd (pkgmgr rm) (flags rm) (rawPMArgs rm) ps
-- -----------------------------------------------------------------------------
-- Command-line flags

0 comments on commit 942eef3

Please sign in to comment.