@@ -105,7 +105,7 @@ import qualified Stack.Upload as Upload
105105import qualified System.Directory as D
106106import System.Environment (getProgName , getArgs , withArgs )
107107import System.Exit
108- import System.FilePath (isRelative , isValid , pathSeparator )
108+ import System.FilePath (isValid , pathSeparator )
109109import System.IO (hIsTerminalDevice , stderr , stdin , stdout , hSetBuffering , BufferMode (.. ), hPutStrLn , hGetEncoding , hSetEncoding )
110110
111111-- | Change the character encoding of the given Handle to transliterate
@@ -789,19 +789,11 @@ execCmd ExecOpts {..} go@GlobalOpts{..} =
789789 pkgopts <- getPkgOpts menv wc pkgs
790790 return (prefix ++ compilerExeName wc, pkgopts ++ args)
791791
792+ runWithPath :: Maybe FilePath -> RIO EnvConfig () -> RIO EnvConfig ()
792793 runWithPath path callback = case path of
793- Nothing -> callback
794- Just p | not (isValid p) -> callback
795- Just p ->
796- if isRelative p
797- then parseRelDir p >>= runInDirectory
798- else parseAbsDir p >>= runInDirectory
799- where
800- runInDirectory :: (Path t Dir ) -> RIO EnvConfig ()
801- runInDirectory directory =
802- withUnliftIO $ \ unlift ->
803- withCurrentDir directory $ unliftIO unlift callback
804-
794+ Nothing -> callback
795+ Just p | not (isValid p) -> throwIO $ InvalidPathForExec p
796+ Just p -> withUnliftIO $ \ ul -> D. withCurrentDirectory p $ unliftIO ul callback
805797
806798-- | Evaluate some haskell code inline.
807799evalCmd :: EvalOpts -> GlobalOpts -> IO ()
@@ -938,6 +930,7 @@ hpcReportCmd hropts go = withBuildConfig go $ generateHpcReportForTargets hropts
938930
939931data MainException = InvalidReExecVersion String String
940932 | UpgradeCabalUnusable
933+ | InvalidPathForExec FilePath
941934 deriving (Typeable )
942935instance Exception MainException
943936instance Show MainException where
@@ -949,3 +942,7 @@ instance Show MainException where
949942 , " ; found: "
950943 , actual]
951944 show UpgradeCabalUnusable = " --upgrade-cabal cannot be used when nix is activated"
945+ show (InvalidPathForExec path) = concat
946+ [ " Got an invalid --cwd argument for stack exec ("
947+ , path
948+ , " )" ]
0 commit comments