ghcup-0.1.14.2: ghc toolchain installer
Copyright(c) Julian Ospald 2020
LicenseLGPL-3.0
Maintainerhasufell@hasufell.de
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

GHCup.Utils.File

Description

This module handles file and executable handling. Some of these functions use sophisticated logging.

Synopsis

Documentation

findExecutable :: Path Rel -> IO (Maybe (Path Abs)) Source #

Find the given executable by searching all *absolute* PATH components. Relative paths in PATH are ignored.

This shouldn't throw IO exceptions, unless getting the environment variable PATH does.

executeOut Source #

Arguments

:: Path b

command as filename, e.g. ls

-> [ByteString]

arguments to the command

-> Maybe (Path Abs)

chdir to this path

-> IO CapturedProcess 

Execute the given command and collect the stdout, stderr and the exit code. The command is run in a subprocess.

execLogged Source #

Arguments

:: (MonadReader AppState m, MonadIO m, MonadThrow m) 
=> ByteString

thing to execute

-> Bool

whether to search PATH for the thing

-> [ByteString]

args for the thing

-> Path Rel

log filename

-> Maybe (Path Abs)

optionally chdir into this

-> Maybe [(ByteString, ByteString)]

optional environment

-> m (Either ProcessError ()) 

captureOutStreams Source #

Arguments

:: IO a

the action to execute in a subprocess

-> IO CapturedProcess 

Capture the stdout and stderr of the given action, which is run in a subprocess. Stdin is closed. You might want to race this to make sure it terminates.

actionWithPipes :: ((Fd, Fd) -> IO b) -> IO b Source #

cleanup :: [Fd] -> IO () Source #

createRegularFileFd :: FileMode -> Path b -> IO Fd Source #

Create a new regular file in write-only mode. The file must not exist.

exec Source #

Arguments

:: ByteString

thing to execute

-> Bool

whether to search PATH for the thing

-> [ByteString]

args for the thing

-> Maybe (Path Abs)

optionally chdir into this

-> Maybe [(ByteString, ByteString)]

optional environment

-> IO (Either ProcessError ()) 

Thin wrapper around executeFile.

searchPath :: [Path Abs] -> Path Rel -> IO (Maybe (Path Abs)) Source #

Search for a file in the search paths.

Catches PermissionDenied and NoSuchThing and returns Nothing.

isShadowed :: Path Abs -> IO (Maybe (Path Abs)) Source #

Check wether a binary is shadowed by another one that comes before it in PATH. Returns the path to said binary, if any.

isInPath :: Path Abs -> IO Bool Source #

Check whether the binary is in PATH. This returns only True if the directory containing the binary is part of PATH.

chmod_755 :: (MonadLogger m, MonadIO m) => Path a -> m () Source #