Safe Haskell | Safe-Infered |
---|
HsShellScript.Misc
- zeros :: Int -> Int -> String
- chomp :: String -> String
- lazy_contents :: String -> IO String
- contents :: String -> IO String
- path_exists :: String -> IO Bool
- path_exists' :: String -> IO Bool
- is_dir :: String -> IO Bool
- is_file :: String -> IO Bool
- getFileStatus' :: FilePath -> IO FileStatus
- fileAccess' :: FilePath -> Bool -> Bool -> Bool -> IO Bool
- temp_file :: Int -> String -> String -> IO FilePath
- temp_dir :: Int -> String -> String -> IO FilePath
- tmp_file :: String -> IO FilePath
- tmp_dir :: String -> IO FilePath
- with_temp_file :: Int -> String -> String -> (Handle -> IO a) -> IO a
- with_temp_dir :: Int -> String -> String -> (FilePath -> IO a) -> IO a
- with_tmp_file :: String -> (Handle -> IO a) -> IO a
- with_tmp_dir :: String -> (FilePath -> IO a) -> IO a
- temp_path :: Int -> String -> String -> IO FilePath
- untilIO :: Monad m => m b -> (b -> m Bool) -> m b
- data Mntent = Mntent {}
- read_mounts :: String -> IO [Mntent]
- read_mtab :: IO [Mntent]
- read_fstab :: IO [Mntent]
- o_CREAT :: CInt
- o_EXCL :: CInt
- with_wd :: FilePath -> IO a -> IO a
- glob :: String -> IO [String]
- hsshellscript_open_nonvariadic :: Ptr CChar -> CInt -> CUInt -> IO CInt
- c_close :: CInt -> IO CInt
- c_mkdir :: Ptr CChar -> CUInt -> IO CInt
- setmntent :: Ptr CChar -> Ptr CChar -> IO (Ptr ())
- endmntent :: Ptr () -> IO CInt
- c_getmntent :: Ptr () -> IO (Ptr ())
- do_glob :: Ptr () -> Ptr CChar -> IO CInt
- globfree :: Ptr () -> IO ()
Documentation
Arguments
:: Int | How many characters to fill up |
-> Int | Value to represent as a string |
-> String | String representation of the value, using the specified number of characters |
Format an Int
with leading zeros. If the string representation of the Inŧ
is longer than the number of characters to fill up, this produces as
many characters as needed.
Arguments
:: String | String to be chomped |
-> String | Same string, except for no newline characters at the end |
Remove trailing newlines. This is silimar to perl's chomp
procedure.
Arguments
:: String | Either the name of a file, or |
-> IO String | The lazily read contents of the file or |
Get contents of a file or of stdin
. This is a simple frontend to
hGetContents
. A file name of "-"
designates stdin. The contents are read
lazily as the string is evaluated.
(The handle which we read from will be in semi-closed state. Once all input has read, it is closed automatically (Haskell Library Report 11.2.1). Therefore we don't need to return it).
lazy_contents path = do h <- if path == "-" then return stdin else openFile path ReadMode hGetContents h
Arguments
:: String | either the name of a file, or |
-> IO String | the contents of the file or of standard input |
Get contents of a file or of stdin
eagerly. This is the
same as lazy_contents
, except for the contents being
read immediately.
Test for the existence of a path. This is the disjunction of
Directory.doesDirectoryExist
and Directory.doesFileExist
. For an dangling symlink, this will return False
.
Test for the existence of a path. This uses System.Posix.Files.getFileStatus
to determine whether the path exists in any form in the file system.
For a dangling symlink, the result is True
.
Test if path points to a directory. This will return True
for a symlink pointing to a directory. It's a shortcut for
Directory.doesDirectoryExist
.
Test if path points to a file. This is a shortcut for
Directory.doesFileExist
.
Arguments
:: FilePath | Path of the file, whose status is to be queried |
-> IO FileStatus | Status of the file |
This is the System.Posix.Files.getFileStatus
function from the GHC libraries, with improved error reporting. The GHC function doesn't include the
file name in the IOError
when the call fails, making error messages much less useful. getFileStatus'
rectifies this.
See getFileStatus
.
fileAccess' :: FilePath -> Bool -> Bool -> Bool -> IO BoolSource
This is the System.Posix.Files.fileAccess
function from the GHC libraries, with improved error reporting. The GHC function doesn't include the
file name in the IOError
when the call fails, making error messages much less useful. fileAccess'
rectifies this.
See fileAccess
.
Arguments
:: Int | Number of random characters to intersperse. Must be large enough, such that most combinations can't already exist. |
-> String | Prefix for the path to generate. |
-> String | Suffix for the path to generate. |
-> IO FilePath | Path of the created file. |
Create a temporary file. This will create a new, empty file, with a path which did not previously exist in the file system. The path consists
of the specified prefix, a sequence of random characters (digits and letters), and the specified suffix. The file is created with read-write
permissions for the user, and no permissons for the group and others. The ownership is set to the effective user ID of the process. The group
ownership is set either to the effective group ID of the process or to the group ID of the parent directory (depending on filesystem type and mount
options on Linux - see open(2)
for details).
See tmp_file
, temp_dir
, with_temp_file
.
Arguments
:: Int | Number of random characters to intersperse. Must be large enough, such that most combinations can't already exist. |
-> String | Prefix for the path to generate. |
-> String | Suffix for the path to generate. |
-> IO FilePath | Generated path. |
Create a temporary directory. This will create a new directory, with a path which did not previously exist in the file system. The path consists of the specified prefix, a sequence of random characters (digits and letters), and the specified suffix. The directory is normally created with read-write-execute permissions for the user, and no permissons for the group and others. But this may be further restricted by the process's umask in the usual way.
The newly created directory will be owned by the effective uid of the process. If the directory containing the it has the set group
id bit set, or if the filesystem is mounted with BSD group semantics, the new directory will inherit the group ownership from its parent;
otherwise it will be owned by the effective gid of the process. (See mkdir(2)
)
See tmp_dir
, temp_file
, with_temp_dir
.
Create a temporary file. This will create a new, empty file, with read-write permissions for the user, and no permissons for the group and others. The path consists of the specified prefix, a dot, and six random characters (digits and letters).
tmp_file prefix = temp_file 6 (prefix ++ ".") ""
See temp_file
, tmp_dir
, with_tmp_file
.
Create a temporary directory. This will create a new directory, with read-write-execute permissions for the user (unless further restricted by the process's umask), and no permissons for the group and others. The path consists of the specified prefix, a dot, and six random characters (digits and letters).
tmp_dir prefix = temp_dir 6 (prefix ++ ".") ""
See temp_dir
, tmp_file
, with_tmp_dir
.
Arguments
:: Int | Number of random characters to intersperse. Must be large enough, such that most combinations can't already exist. |
-> String | Prefix for the path to generate. |
-> String | Suffix for the path to generate. |
-> (Handle -> IO a) | Action to perform. |
-> IO a | Returns the value returned by the action. |
Create and open a temporary file, perform some action with it, and delete it afterwards. This is a front end to the temp_file
function. The file
and its path are created in the same way. The IO action is passed a handle of the new file. When it finishes - normally or with an exception -
the file is deleted.
See temp_file
, with_tmp_file
, with_temp_dir
.
Arguments
:: Int | Number of random characters to intersperse. Must be large enough, such that most combinations can't already exist. |
-> String | Prefix for the path to generate. |
-> String | Suffix for the path to generate. |
-> (FilePath -> IO a) | Action to perform. |
-> IO a | Returns the value returned by the action. |
Create a temporary directory, perform some action with it, and delete it afterwards. This is a front end to the temp_dir
function. The directory
and its path are created in the same way. The IO action is passed the path of the new directory. When it finishes - normally or with an exception -
the directory is deleted.
The action must clean up any files it creates inside the directory by itself. with_temp_dir
doesn't delete any files inside, so the directory
could be removed. If the directory isn't empty, an IOError
results (with the path filled in). When the action throws an exception, and the
temporary directory cannot be removed, then the exception is passed through, rather than replacing it with the IOError. (This is because it's
probably exactly because of that exception that the directory isn't empty and can't be removed).
See temp_dir
, with_tmp_dir
, with_temp_file
.
Arguments
:: String | Prefix for the path to generate. |
-> (Handle -> IO a) | Action to perform. |
-> IO a | Returns the value returned by the action. |
Create and open a temporary file, perform some action with it, and delete it afterwards. This is a front end to the tmp_file
function. The file
and its path are created in the same way. The IO action is passed a handle of the new file. When it finishes - normally or with an exception -
the file is deleted.
See tmp_file
, with_temp_file
, with_tmp_dir
.
Arguments
:: String | Prefix for the path to generate. |
-> (FilePath -> IO a) | Action to perform. |
-> IO a | Returns the value returned by the action. |
Create a temporary directory, perform some action with it, and delete it afterwards. This is a front end to the tmp_dir
function. The directory
and its path are created in the same way. The IO action is passed the path of the new directory. When it finishes - normally or with an exception -
the directory is deleted.
The action must clean up any files it creates inside the directory by itself. with_temp_dir
doesn't delete any files inside, so the directory
could be removed. If the directory isn't empty, an IOError
results (with the path filled in). When the action throws an exception, and the
temporary directory cannot be removed, then the exception is passed through, rather than replacing it with the IOError. (This is because it's
probably exactly because of that exception that the directory isn't empty and can't be removed).
with_tmp_dir prefix io = with_temp_dir 6 (prefix ++ ".") "" io
See tmp_dir
, with_temp_dir
, with_tmp_file
.
Arguments
:: Int | Number of random characters to intersperse. Must be large enough, such that most combinations can't already exist. |
-> String | Prefix for the path to generate. |
-> String | Suffix for the path to generate. |
-> IO FilePath | Generated path. |
Create a temporary path. This will generate a path which does not yet exist in the file system. It consists of the specified prefix, a sequence of random characters (digits and letters), and the specified suffix.
Avoid relying on the generated path not to exist in the file system. Or else you'll get a potential race condition, since some other process might
create the path after temp_path
, before you use it. This is a security risk. The global random number generator (Random.randomRIO
) is used to
generate the random characters. These might not be that random after all, and could potentially be guessed. Rather use temp_file
or temp_dir
.
One entry of mount information. This is the same as struct mntent
from <mntent.h>
.
A list of these is returned by the functions which read mount information.
See read_mounts
, read_mtab
, read_fstab
.
Constructors
Mntent | |
Arguments
:: String | File to read (typically |
-> IO [Mntent] | Mount information in that file |
Read mount information. This is a front end to the setmntent(3)
, getmntent(3)
, endmntent(3)
system library functions.
When the setmntent
call fails, the errno
value is converted to an IOError
and thrown.
See read_mtab
, read_fstab
.
read_fstab :: IO [Mntent]Source
Change the working directory temporarily. This executes the specified IO action with a new working directory, and restores it afterwards (exception-safely).
This is an interface to the POSIX glob
function, which does wildcard expansion
in paths. The list of matched paths is returned. It's empty
for no match (rather than the original pattern). In case anything goes wrong
(such as permission denied), an IOError is thrown.
This does not do tilde expansion, which is done (among many unwanted other
things) by wordexp
. The only flag used for the call to glob
is GLOB_ERR
.
The behaviour in case of non-existing path components is inconsistent in the
GNU version of the underlying glob
function. glob /doesnt_exist/foo
will return
the empty list, whereas glob /doesnt_exist/*
causes a No such file or directory
IOError.
See man pages glob(3)
and wordexp(3)
.