Split GHCup.Utils.File module

This commit is contained in:
Julian Ospald 2021-11-05 22:30:47 +01:00
parent c05876cc60
commit 34910f853b
Signed by: hasufell
GPG Key ID: 3786C5262ECB4A3F
18 changed files with 82 additions and 66 deletions

View File

@ -15,7 +15,7 @@ import GHCup.Types hiding ( LeanAppState(..) )
import GHCup.Utils import GHCup.Utils
import GHCup.Utils.Logger import GHCup.Utils.Logger
import GHCup.Utils.Prelude ( decUTF8Safe ) import GHCup.Utils.Prelude ( decUTF8Safe )
import GHCup.Utils.File import GHCup.System.Process
import Brick import Brick
import Brick.Widgets.Border import Brick.Widgets.Border

View File

@ -35,7 +35,7 @@ import GHCup.Utils
import Data.Versions import Data.Versions
import URI.ByteString (serializeURIRef') import URI.ByteString (serializeURIRef')
import GHCup.Utils.Prelude import GHCup.Utils.Prelude
import GHCup.Utils.File (exec) import GHCup.System.Process (exec)
import Data.Char (toLower) import Data.Char (toLower)

View File

@ -13,13 +13,13 @@ module GHCup.OptParse.Compile where
import GHCup import GHCup
import GHCup.Errors import GHCup.Errors
import GHCup.Utils.File
import GHCup.Types import GHCup.Types
import GHCup.Types.Optics import GHCup.Types.Optics
import GHCup.Utils import GHCup.Utils
import GHCup.Utils.Logger import GHCup.Utils.Logger
import GHCup.OptParse.Common import GHCup.OptParse.Common
import GHCup.Utils.String.QQ import GHCup.Utils.String.QQ
import GHCup.System.Process
#if !MIN_VERSION_base(4,13,0) #if !MIN_VERSION_base(4,13,0)
import Control.Monad.Fail ( MonadFail ) import Control.Monad.Fail ( MonadFail )

View File

@ -20,6 +20,7 @@ import GHCup.Types
import GHCup.Utils.Prelude import GHCup.Utils.Prelude
import GHCup.Utils.Dirs import GHCup.Utils.Dirs
import GHCup.Utils.Logger import GHCup.Utils.Logger
import GHCup.System.Process
#if !MIN_VERSION_base(4,13,0) #if !MIN_VERSION_base(4,13,0)
import Control.Monad.Fail ( MonadFail ) import Control.Monad.Fail ( MonadFail )
@ -36,7 +37,6 @@ import Text.PrettyPrint.HughesPJClass ( prettyShow )
import qualified Data.Text as T import qualified Data.Text as T
import Control.Exception.Safe (MonadMask) import Control.Exception.Safe (MonadMask)
import GHCup.Utils.File
import Language.Haskell.TH import Language.Haskell.TH

View File

@ -17,9 +17,9 @@ import GHCup.OptParse.Common
import GHCup import GHCup
import GHCup.Errors import GHCup.Errors
import GHCup.Types import GHCup.Types
import GHCup.Utils.File
import GHCup.Utils.Logger import GHCup.Utils.Logger
import GHCup.Utils.String.QQ import GHCup.Utils.String.QQ
import GHCup.System.Process
import Codec.Archive import Codec.Archive
#if !MIN_VERSION_base(4,13,0) #if !MIN_VERSION_base(4,13,0)

View File

@ -61,8 +61,9 @@ library
GHCup.Types.Optics GHCup.Types.Optics
GHCup.Utils GHCup.Utils
GHCup.Utils.Dirs GHCup.Utils.Dirs
GHCup.Utils.File GHCup.System.Process
GHCup.Utils.File.Common GHCup.System.Directory
GHCup.System.Process.Common
GHCup.Utils.Logger GHCup.Utils.Logger
GHCup.Utils.MegaParsec GHCup.Utils.MegaParsec
GHCup.Utils.Prelude GHCup.Utils.Prelude
@ -152,7 +153,7 @@ library
if os(windows) if os(windows)
cpp-options: -DIS_WINDOWS cpp-options: -DIS_WINDOWS
other-modules: other-modules:
GHCup.Utils.File.Windows GHCup.System.Process.Windows
GHCup.Utils.Prelude.Windows GHCup.Utils.Prelude.Windows
GHCup.Utils.Windows GHCup.Utils.Windows
@ -163,7 +164,7 @@ library
else else
other-modules: other-modules:
GHCup.Utils.File.Posix GHCup.System.Process.Posix
GHCup.Utils.Posix GHCup.Utils.Posix
GHCup.Utils.Prelude.Posix GHCup.Utils.Prelude.Posix
System.Console.Terminal.Common System.Console.Terminal.Common

View File

@ -33,12 +33,13 @@ import GHCup.Types
import GHCup.Types.JSON ( ) import GHCup.Types.JSON ( )
import GHCup.Types.Optics import GHCup.Types.Optics
import GHCup.Utils import GHCup.Utils
import GHCup.Utils.File
import GHCup.Utils.Logger import GHCup.Utils.Logger
import GHCup.Utils.Prelude import GHCup.Utils.Prelude
import GHCup.Utils.String.QQ import GHCup.Utils.String.QQ
import GHCup.Utils.Version.QQ import GHCup.Utils.Version.QQ
import GHCup.Version import GHCup.Version
import GHCup.System.Directory
import GHCup.System.Process
import Codec.Archive ( ArchiveResult ) import Codec.Archive ( ArchiveResult )
import Control.Applicative import Control.Applicative

View File

@ -34,7 +34,7 @@ import GHCup.Types
import GHCup.Types.Optics import GHCup.Types.Optics
import GHCup.Types.JSON ( ) import GHCup.Types.JSON ( )
import GHCup.Utils.Dirs import GHCup.Utils.Dirs
import GHCup.Utils.File import GHCup.System.Process
import GHCup.Utils.Logger import GHCup.Utils.Logger
import GHCup.Utils.Prelude import GHCup.Utils.Prelude
import GHCup.Version import GHCup.Version

View File

@ -23,7 +23,7 @@ import GHCup.Errors
import GHCup.Types import GHCup.Types
import GHCup.Types.Optics import GHCup.Types.Optics
import GHCup.Types.JSON ( ) import GHCup.Types.JSON ( )
import GHCup.Utils.File import GHCup.System.Process
import GHCup.Utils.Logger import GHCup.Utils.Logger
import GHCup.Utils.Prelude import GHCup.Utils.Prelude
import GHCup.Utils.String.QQ import GHCup.Utils.String.QQ

View File

@ -3,7 +3,7 @@
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE ViewPatterns #-}
module GHCup.Utils.File.Common where module GHCup.System.Directory where
import GHCup.Utils.Prelude import GHCup.Utils.Prelude
@ -12,42 +12,15 @@ import Data.Maybe
import Data.Text ( Text ) import Data.Text ( Text )
import Data.Void import Data.Void
import GHC.IO.Exception import GHC.IO.Exception
import Optics hiding ((<|), (|>))
import System.Directory import System.Directory
import System.FilePath import System.FilePath
import Text.PrettyPrint.HughesPJClass hiding ( (<>) )
import Text.Regex.Posix import Text.Regex.Posix
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.ByteString.Lazy as BL
import qualified Text.Megaparsec as MP import qualified Text.Megaparsec as MP
data ProcessError = NonZeroExit Int FilePath [String]
| PTerminated FilePath [String]
| PStopped FilePath [String]
| NoSuchPid FilePath [String]
deriving Show
instance Pretty ProcessError where
pPrint (NonZeroExit e exe args) =
text "Process" <+> pPrint exe <+> text "with arguments" <+> pPrint args <+> text "failed with exit code" <+> text (show e <> ".")
pPrint (PTerminated exe args) =
text "Process" <+> pPrint exe <+> text "with arguments" <+> pPrint args <+> text "terminated."
pPrint (PStopped exe args) =
text "Process" <+> pPrint exe <+> text "with arguments" <+> pPrint args <+> text "stopped."
pPrint (NoSuchPid exe args) =
text "Could not find PID for process running " <+> pPrint exe <+> text " with arguments " <+> text (show args) <+> text "."
data CapturedProcess = CapturedProcess
{ _exitCode :: ExitCode
, _stdOut :: BL.ByteString
, _stdErr :: BL.ByteString
}
deriving (Eq, Show)
makeLenses ''CapturedProcess

View File

@ -1,4 +1,4 @@
module GHCup.Utils.File.Common where module GHCup.System.Directory where
import Text.Regex.Posix import Text.Regex.Posix

View File

@ -0,0 +1,19 @@
{-# LANGUAGE CPP #-}
module GHCup.System.Process (
module GHCup.System.Process.Common,
#if IS_WINDOWS
module GHCup.System.Process.Windows
#else
module GHCup.System.Process.Posix
#endif
) where
#if IS_WINDOWS
import GHCup.System.Process.Windows
#else
import GHCup.System.Process.Posix
#endif
import GHCup.System.Process.Common

View File

@ -0,0 +1,37 @@
{-# LANGUAGE TemplateHaskell #-}
module GHCup.System.Process.Common where
import GHC.IO.Exception
import Optics hiding ((<|), (|>))
import Text.PrettyPrint.HughesPJClass hiding ( (<>) )
import qualified Data.ByteString.Lazy as BL
data ProcessError = NonZeroExit Int FilePath [String]
| PTerminated FilePath [String]
| PStopped FilePath [String]
| NoSuchPid FilePath [String]
deriving Show
instance Pretty ProcessError where
pPrint (NonZeroExit e exe args) =
text "Process" <+> pPrint exe <+> text "with arguments" <+> pPrint args <+> text "failed with exit code" <+> text (show e <> ".")
pPrint (PTerminated exe args) =
text "Process" <+> pPrint exe <+> text "with arguments" <+> pPrint args <+> text "terminated."
pPrint (PStopped exe args) =
text "Process" <+> pPrint exe <+> text "with arguments" <+> pPrint args <+> text "stopped."
pPrint (NoSuchPid exe args) =
text "Could not find PID for process running " <+> pPrint exe <+> text " with arguments " <+> text (show args) <+> text "."
data CapturedProcess = CapturedProcess
{ _exitCode :: ExitCode
, _stdOut :: BL.ByteString
, _stdErr :: BL.ByteString
}
deriving (Eq, Show)
makeLenses ''CapturedProcess

View File

@ -2,7 +2,7 @@
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleContexts #-}
{-| {-|
Module : GHCup.Utils.File.Posix Module : GHCup.System.Process.Posix
Description : File and unix APIs Description : File and unix APIs
Copyright : (c) Julian Ospald, 2020 Copyright : (c) Julian Ospald, 2020
License : LGPL-3.0 License : LGPL-3.0
@ -13,13 +13,13 @@ Portability : POSIX
This module handles file and executable handling. This module handles file and executable handling.
Some of these functions use sophisticated logging. Some of these functions use sophisticated logging.
-} -}
module GHCup.Utils.File.Posix where module GHCup.System.Process.Posix where
import GHCup.Utils.File.Common
import GHCup.Utils.Prelude import GHCup.Utils.Prelude
import GHCup.Utils.Logger import GHCup.Utils.Logger
import GHCup.Types import GHCup.Types
import GHCup.Types.Optics import GHCup.Types.Optics
import GHCup.System.Process.Common
import Control.Concurrent import Control.Concurrent
import Control.Concurrent.Async import Control.Concurrent.Async

View File

@ -2,7 +2,7 @@
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleContexts #-}
{-| {-|
Module : GHCup.Utils.File.Windows Module : GHCup.System.Process.Windows
Description : File and windows APIs Description : File and windows APIs
Copyright : (c) Julian Ospald, 2020 Copyright : (c) Julian Ospald, 2020
License : LGPL-3.0 License : LGPL-3.0
@ -13,13 +13,14 @@ Portability : Windows
This module handles file and executable handling. This module handles file and executable handling.
Some of these functions use sophisticated logging. Some of these functions use sophisticated logging.
-} -}
module GHCup.Utils.File.Windows where module GHCup.System.Process.Windows where
import {-# SOURCE #-} GHCup.Utils ( getLinkTarget, pathIsLink ) import {-# SOURCE #-} GHCup.Utils ( getLinkTarget, pathIsLink )
import GHCup.Utils.Dirs import GHCup.Utils.Dirs
import GHCup.Utils.File.Common
import GHCup.Types import GHCup.Types
import GHCup.Types.Optics import GHCup.Types.Optics
import GHCup.System.Directory
import GHCup.System.Process.Common
import Control.Concurrent import Control.Concurrent
import Control.DeepSeq import Control.DeepSeq

View File

@ -42,11 +42,12 @@ import GHCup.Types
import GHCup.Types.Optics import GHCup.Types.Optics
import GHCup.Types.JSON ( ) import GHCup.Types.JSON ( )
import GHCup.Utils.Dirs import GHCup.Utils.Dirs
import GHCup.Utils.File
import GHCup.Utils.Logger import GHCup.Utils.Logger
import GHCup.Utils.MegaParsec import GHCup.Utils.MegaParsec
import GHCup.Utils.Prelude import GHCup.Utils.Prelude
import GHCup.Utils.String.QQ import GHCup.Utils.String.QQ
import GHCup.System.Directory
import GHCup.System.Process
import Codec.Archive hiding ( Directory ) import Codec.Archive hiding ( Directory )
import Control.Applicative import Control.Applicative

View File

@ -1,17 +0,0 @@
{-# LANGUAGE CPP #-}
module GHCup.Utils.File (
module GHCup.Utils.File.Common,
#if IS_WINDOWS
module GHCup.Utils.File.Windows
#else
module GHCup.Utils.File.Posix
#endif
) where
import GHCup.Utils.File.Common
#if IS_WINDOWS
import GHCup.Utils.File.Windows
#else
import GHCup.Utils.File.Posix
#endif

View File

@ -18,7 +18,7 @@ module GHCup.Utils.Logger where
import GHCup.Types import GHCup.Types
import GHCup.Types.Optics import GHCup.Types.Optics
import {-# SOURCE #-} GHCup.Utils.File.Common import {-# SOURCE #-} GHCup.System.Directory
import GHCup.Utils.String.QQ import GHCup.Utils.String.QQ
import Control.Exception.Safe import Control.Exception.Safe