ContentsIndex
HsShellScript.Misc
Synopsis
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
data Mntent = Mntent {
mnt_fsname :: String
mnt_dir :: String
mnt_type :: String
mnt_opts :: String
mnt_freq :: Int
mnt_passno :: Int
}
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
zeros
:: Inthow many characters to fill up
-> Intvalue to represent as a string
-> Stringstring representation of the value, using the specified number of characters
Format an Int with leading zeros.
chomp
:: StringString to be chomped
-> StringSame string, except for no newline characters at the end
Remove trailing newlines. This is silimar to perl's chomp procedure.
lazy_contents
:: StringEither the name of a file, or "-"
-> IO StringThe lazily read contents of the file or stdin.

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
contents
:: Stringeither the name of a file, or "-" for stdin
-> IO Stringthe 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.
path_exists
:: StringPath
-> IO BoolWhether the path exists in the file system
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.
path_exists'
:: StringPath
-> IO BoolWhether the path exists in the file system
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.
is_dir
:: StringPath
-> IO BoolWhether the path exists and points to a directory.
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.
is_file
:: StringPath
-> IO BoolWhether the path exists and points to a file.
Test if path points to a file. This is a shortcut for Directory.doesFileExist.
getFileStatus'
:: FilePathPath of the file, whose status is to be queried
-> IO FileStatusStatus 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 System.Posix.Files.getFileStatus.

fileAccess' :: FilePath -> Bool -> Bool -> Bool -> IO Bool

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 System.Posix.Files.fileAccess.

temp_file
:: IntNumber of random characters to intersperse. Must be large enough, such that most combinations can't already exist.
-> StringPrefix for the path to generate.
-> StringSuffix for the path to generate.
-> IO FilePathPath 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.

temp_dir
:: IntNumber of random characters to intersperse. Must be large enough, such that most combinations can't already exist.
-> StringPrefix for the path to generate.
-> StringSuffix for the path to generate.
-> IO FilePathGenerated 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.

tmp_file
:: StringPrefix for the path to generate.
-> IO FilePathPath of the created file.

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.

tmp_dir
:: StringPrefix for the path to generate.
-> IO FilePathPath of the created directory.

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.

with_temp_file
::
=> IntNumber of random characters to intersperse. Must be large enough, such that most combinations can't already exist.
-> StringPrefix for the path to generate.
-> StringSuffix for the path to generate.
-> Handle -> IO aAction to perform.
-> IO aReturns 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.

with_temp_dir
::
=> IntNumber of random characters to intersperse. Must be large enough, such that most combinations can't already exist.
-> StringPrefix for the path to generate.
-> StringSuffix for the path to generate.
-> FilePath -> IO aAction to perform.
-> IO aReturns 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.

with_tmp_file
::
=> StringPrefix for the path to generate.
-> Handle -> IO aAction to perform.
-> IO aReturns 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.

with_tmp_dir
::
=> StringPrefix for the path to generate.
-> FilePath -> IO aAction to perform.
-> IO aReturns 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.

temp_path
:: IntNumber of random characters to intersperse. Must be large enough, such that most combinations can't already exist.
-> StringPrefix for the path to generate.
-> StringSuffix for the path to generate.
-> IO FilePathGenerated 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.

See temp_file, temp_dir.

data Mntent

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
mnt_fsname :: StringDevice file ("name of mounted file system")
mnt_dir :: StringMount point
mnt_type :: StringWhich kind of file system ("see mntent.h")
mnt_opts :: StringMount options ("see mntent.h")
mnt_freq :: IntDump frequency in days
mnt_passno :: Int"Pass number on parallel fsck"
show/hide Instances
Eq Mntent
Read Mntent
Show Mntent
Typeable Mntent
read_mounts
:: StringFile to read (typically /etc/mtab or /etc/fstab)
-> 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_mtab :: IO [Mntent]

Get the currently mounted file systems.

read_mtab = read_mounts "/etc/mtab"

See read_mounts.

read_fstab :: IO [Mntent]

Get the system wide file system table.

read_fstab = read_mounts "/etc/fstab"

See read_mounts.

o_CREAT :: CInt
o_EXCL :: CInt
with_wd
::
=> FilePathNew working directory
-> IO aAction to run
-> IO a
Change the working directory temporarily. This executes the specified IO action with a new working directory, and restores it afterwards (exception-safely).
glob
:: StringPattern
-> IO [String]Sorted list of matching paths

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).

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 ()
Produced by Haddock version 2.4.2