hsfm-gtk

Safe HaskellNone
LanguageHaskell2010

HSFM.FileSystem.FileType

Description

This module provides a data type for representing directories/files in a well-typed and convenient way. This is useful to gather and save information about a file, so the information can be easily processed in e.g. a GUI.

However, it's not meant to be used to interact with low-level functions that copy files etc, since there's no guarantee that the in-memory representation of the type still matches what is happening on filesystem level.

If you interact with low-level libraries, you must not pattern match on the `File a` type. Instead, you should only use the saved path and make no assumptions about the file the path might or might not point to.

Synopsis

Documentation

data File a Source #

The String in the path field is always a full path. The free type variable is used in the File/Dir constructor and can hold Handles, Strings representing a file's contents or anything else you can think of. We catch any IO errors in the Failed constructor.

Constructors

Failed 

Fields

  • path :: !(Path Abs)
     
  • err :: IOError
     
Dir 

Fields

RegFile 

Fields

SymLink 

Fields

BlockDev 

Fields

CharDev 

Fields

NamedPipe 

Fields

Socket 

Fields

Instances

Eq a => Eq (File a) Source # 

Methods

(==) :: File a -> File a -> Bool

(/=) :: File a -> File a -> Bool

Ord (File FileInfo) Source #

First compare constructors: Failed < Dir < File... Then compare name... Then compare free variable parameter of File constructors

Show a => Show (File a) Source # 

Methods

showsPrec :: Int -> File a -> ShowS

show :: File a -> String

showList :: [File a] -> ShowS

data FileInfo Source #

Low-level file information.

Constructors

FileInfo 

Fields

Instances

Eq FileInfo Source # 

Methods

(==) :: FileInfo -> FileInfo -> Bool

(/=) :: FileInfo -> FileInfo -> Bool

Ord FileInfo Source # 

Methods

compare :: FileInfo -> FileInfo -> Ordering

(<) :: FileInfo -> FileInfo -> Bool

(<=) :: FileInfo -> FileInfo -> Bool

(>) :: FileInfo -> FileInfo -> Bool

(>=) :: FileInfo -> FileInfo -> Bool

max :: FileInfo -> FileInfo -> FileInfo

min :: FileInfo -> FileInfo -> FileInfo

Show FileInfo Source # 

Methods

showsPrec :: Int -> FileInfo -> ShowS

show :: FileInfo -> String

showList :: [FileInfo] -> ShowS

Ord (File FileInfo) Source #

First compare constructors: Failed < Dir < File... Then compare name... Then compare free variable parameter of File constructors

pattern FileLike :: File FileInfo -> File FileInfo Source #

Matches on any non-directory kind of files, excluding symlinks.

pattern DirList :: forall t. (Foldable t, Functor t) => t (File FileInfo) -> t (File FileInfo) Source #

Matches a list of directories or symlinks pointing to directories.

pattern FileLikeList :: forall t. (Foldable t, Functor t) => t (File FileInfo) -> t (File FileInfo) Source #

Matches a list of any non-directory kind of files or symlinks pointing to such.

pattern FileLikeSym :: File FileInfo -> File FileInfo Source #

Matches on symlinks pointing to file-like files only.

pattern BrokenSymlink :: File FileInfo -> File FileInfo Source #

Matches on broken symbolic links.

pattern DirOrSym :: File FileInfo -> File FileInfo Source #

Matches on directories or symlinks pointing to directories. If the symlink is pointing to a symlink pointing to a directory, then it will return True, but also return the first element in the symlink- chain, not the last.

pattern DirSym :: File FileInfo -> File FileInfo Source #

Matches on symlinks pointing to directories only.

pattern FileLikeOrSym :: File FileInfo -> File FileInfo Source #

Matches on any non-directory kind of files or symlinks pointing to such. If the symlink is pointing to a symlink pointing to such a file, then it will return True, but also return the first element in the symlink- chain, not the last.

readFile :: (Path Abs -> IO a) -> Path Abs -> IO (File a) Source #

Reads a file or directory Path into an AnchoredFile, filling the free variables via the given function.

readDirectoryContents Source #

Arguments

:: (Path Abs -> IO a)

fills free a variable

-> Path Abs

path to read

-> IO [File a] 

Get the contents of a given directory and return them as a list of AnchoredFile.

getContents :: (Path Abs -> IO a) -> File FileInfo -> IO [File a] Source #

A variant of readDirectoryContents where the second argument is a File. If a non-directory is passed returns an empty list.

goUp :: File FileInfo -> IO (File FileInfo) Source #

Go up one directory in the filesystem hierarchy.

goUp' :: Path Abs -> IO (File FileInfo) Source #

Go up one directory in the filesystem hierarchy.

anyFailed :: [File a] -> Bool Source #

True if any Failed constructors in the tree.

successful :: [File a] -> Bool Source #

True if there are no Failed constructors in the tree.

failed :: File a -> Bool Source #

Returns true if argument is a Failed constructor.

failures :: [File a] -> [File a] Source #

Returns a list of Failed constructors only.

isFileC :: File a -> Bool Source #

isDirC :: File a -> Bool Source #

isSymC :: File a -> Bool Source #

isBlockC :: File a -> Bool Source #

isCharC :: File a -> Bool Source #

isNamedC :: File a -> Bool Source #

isSocketC :: File a -> Bool Source #

getFileInfo :: Path Abs -> IO FileInfo Source #

Gets all file information.

handleDT :: Path Abs -> IO (File a) -> IO (File a) Source #

isBrokenSymlink :: File FileInfo -> Bool Source #

Checks if a symlink is broken by examining the constructor of the symlink destination.

When called on a non-symlink, returns False.

packModTime :: File FileInfo -> String Source #

Pack the modification time into a string.

packAccessTime :: File FileInfo -> String Source #

Pack the modification time into a string.

epochToString :: EpochTime -> String Source #

packPermissions :: File FileInfo -> String Source #

Pack the permissions into a string, similar to what "ls -l" does.

packFileType :: File a -> String Source #

fromFreeVar :: Default d => (a -> d) -> File a -> d Source #

Apply a function on the free variable. If there is no free variable for the given constructor the value from the Default class is used.

getFPasStr :: File a -> String Source #

getFreeVar :: File a -> Maybe a Source #

Gets the free variable. Returns Nothing if the constructor is of Failed.