System.IO.HVFS

MissingH-1.4.0.1: Large utility library

Copyright | Copyright (C) 2004-2011 John Goerzen
License | BSD3
Maintainer | John Goerzen <jgoerzen@complete.org>
Stability | provisional
Portability | portable
Safe Haskell | Safe
Language | Haskell98

System.IO.HVFS

Contents

- Implementation Classes / Types
- Re-exported types from other modules
- Orphan instances

Description

Haskell Virtual FS -- generic support for real or virtual filesystem in Haskell

Copyright (c) 2004-2005 John Goerzen, jgoerzen@complete.org

The idea of this module is to provide virtualization of filesystem calls. In addition to the "real" system filesystem, you can also provide access to other, virtual, filesystems using the same set of calls. Examples of such virtual filesystems might include a remote FTP server, WebDAV server, a local Hashtable, a ConfigParser object, or any other data structure you can represent as a tree of named nodes containing strings.

Each `HVFS` function takes a `HVFS` "handle" (`HVFS` instance) as its first parameter. If you wish to operate on the standard system filesystem, you can just use `SystemFS`.

The MissingH.HVFS.IO.InstanceHelpers module contains some code to help you make your own HVFS instances.

The `HVFSOpenable` class works together with the System.IO.HVIO module to provide a complete virtual filesystem and I/O model that allows you to open up virtual filesystem files and act upon them in a manner similar to standard Handles.

Synopsis

- class Show a => HVFS a where
- class Show a => HVFSStat a where
- class HVFS a => HVFSOpenable a where
- data HVFSOpenEncap = HVIO a => HVFSOpenEncap a
- data HVFSStatEncap = HVFSStat a => HVFSStatEncap a
- withStat :: forall b. HVFSStatEncap -> (forall a. HVFSStat a => a -> b) -> b
- withOpen :: forall b. HVFSOpenEncap -> (forall a. HVIO a => a -> b) -> b
- data SystemFS = SystemFS
- type FilePath = String
- type DeviceID = CDev
- type FileID = CIno
- type FileMode = CMode
- type LinkCount = CNlink
- type UserID = CUid
- type GroupID = CGid
- type FileOffset = COff
- type EpochTime = CTime
- data IOMode :: *

# Implementation Classes / Types

class Show a => HVFS a where #

The main HVFS class.

Default implementations of these functions are provided:

- `vGetModificationTime` -- implemented in terms of `vGetFileStatus`
- `vRaiseError`
- `vDoesFileExist` -- implemented in terms of `vGetFileStatus`
- `vDoesDirectoryExist` -- implemented in terms of `vGetFileStatus`
- `vDoesExist` -- implemented in terms of `vGetSymbolicLinkStatus`
- `vGetSymbolicLinkStatus` -- set to call `vGetFileStatus`.

Default implementations of all other functions will generate an isIllegalOperation error, since they are assumed to be un-implemented.

You should always provide at least a `vGetFileStatus` call, and almost certainly several of the others.

Most of these functions correspond to functions in System.Directory or System.Posix.Files. Please see detailed documentation on them there.

Minimal complete definition

vGetFileStatus

Methods

vGetCurrentDirectory :: a -> IO FilePath #

vSetCurrentDirectory :: a -> FilePath -> IO () #

vGetDirectoryContents :: a -> FilePath -> IO [FilePath] #

vDoesFileExist :: a -> FilePath -> IO Bool #

vDoesDirectoryExist :: a -> FilePath -> IO Bool #

vDoesExist :: a -> FilePath -> IO Bool #

True if the file exists, regardless of what type it is. This is even True if the given path is a broken symlink.

vCreateDirectory :: a -> FilePath -> IO () #

vRemoveDirectory :: a -> FilePath -> IO () #

vRenameDirectory :: a -> FilePath -> FilePath -> IO () #

vRemoveFile :: a -> FilePath -> IO () #

vRenameFile :: a -> FilePath -> FilePath -> IO () #

vGetFileStatus :: a -> FilePath -> IO HVFSStatEncap #

vGetSymbolicLinkStatus :: a -> FilePath -> IO HVFSStatEncap #

vGetModificationTime :: a -> FilePath -> IO ClockTime #

vRaiseError :: a -> IOErrorType -> String -> Maybe FilePath -> IO c #

Raise an error relating to actions on this class.

vCreateSymbolicLink :: a -> FilePath -> FilePath -> IO () #

vReadSymbolicLink :: a -> FilePath -> IO FilePath #

vCreateLink :: a -> FilePath -> FilePath -> IO () #

Instances

HVFS SystemFS # |
Methods vGetCurrentDirectory :: SystemFS -> IO FilePath # vSetCurrentDirectory :: SystemFS -> FilePath -> IO () # vGetDirectoryContents :: SystemFS -> FilePath -> IO [FilePath] # vDoesFileExist :: SystemFS -> FilePath -> IO Bool # vDoesDirectoryExist :: SystemFS -> FilePath -> IO Bool # vDoesExist :: SystemFS -> FilePath -> IO Bool # vCreateDirectory :: SystemFS -> FilePath -> IO () # vRemoveDirectory :: SystemFS -> FilePath -> IO () # vRenameDirectory :: SystemFS -> FilePath -> FilePath -> IO () # vRemoveFile :: SystemFS -> FilePath -> IO () # vRenameFile :: SystemFS -> FilePath -> FilePath -> IO () # vGetFileStatus :: SystemFS -> FilePath -> IO HVFSStatEncap # vGetSymbolicLinkStatus :: SystemFS -> FilePath -> IO HVFSStatEncap # vGetModificationTime :: SystemFS -> FilePath -> IO ClockTime # vRaiseError :: SystemFS -> IOErrorType -> String -> Maybe FilePath -> IO c # vCreateSymbolicLink :: SystemFS -> FilePath -> FilePath -> IO () # vReadSymbolicLink :: SystemFS -> FilePath -> IO FilePath # vCreateLink :: SystemFS -> FilePath -> FilePath -> IO () #
HVFS MemoryVFS # |
Methods vGetCurrentDirectory :: MemoryVFS -> IO FilePath # vSetCurrentDirectory :: MemoryVFS -> FilePath -> IO () # vGetDirectoryContents :: MemoryVFS -> FilePath -> IO [FilePath] # vDoesFileExist :: MemoryVFS -> FilePath -> IO Bool # vDoesDirectoryExist :: MemoryVFS -> FilePath -> IO Bool # vDoesExist :: MemoryVFS -> FilePath -> IO Bool # vCreateDirectory :: MemoryVFS -> FilePath -> IO () # vRemoveDirectory :: MemoryVFS -> FilePath -> IO () # vRenameDirectory :: MemoryVFS -> FilePath -> FilePath -> IO () # vRemoveFile :: MemoryVFS -> FilePath -> IO () # vRenameFile :: MemoryVFS -> FilePath -> FilePath -> IO () # vGetFileStatus :: MemoryVFS -> FilePath -> IO HVFSStatEncap # vGetSymbolicLinkStatus :: MemoryVFS -> FilePath -> IO HVFSStatEncap # vGetModificationTime :: MemoryVFS -> FilePath -> IO ClockTime # vRaiseError :: MemoryVFS -> IOErrorType -> String -> Maybe FilePath -> IO c # vCreateSymbolicLink :: MemoryVFS -> FilePath -> FilePath -> IO () # vReadSymbolicLink :: MemoryVFS -> FilePath -> IO FilePath # vCreateLink :: MemoryVFS -> FilePath -> FilePath -> IO () #
HVFS a => HVFS (HVFSChroot a) # |
Methods vGetCurrentDirectory :: HVFSChroot a -> IO FilePath # vSetCurrentDirectory :: HVFSChroot a -> FilePath -> IO () # vGetDirectoryContents :: HVFSChroot a -> FilePath -> IO [FilePath] # vDoesFileExist :: HVFSChroot a -> FilePath -> IO Bool # vDoesDirectoryExist :: HVFSChroot a -> FilePath -> IO Bool # vDoesExist :: HVFSChroot a -> FilePath -> IO Bool # vCreateDirectory :: HVFSChroot a -> FilePath -> IO () # vRemoveDirectory :: HVFSChroot a -> FilePath -> IO () # vRenameDirectory :: HVFSChroot a -> FilePath -> FilePath -> IO () # vRemoveFile :: HVFSChroot a -> FilePath -> IO () # vRenameFile :: HVFSChroot a -> FilePath -> FilePath -> IO () # vGetFileStatus :: HVFSChroot a -> FilePath -> IO HVFSStatEncap # vGetSymbolicLinkStatus :: HVFSChroot a -> FilePath -> IO HVFSStatEncap # vGetModificationTime :: HVFSChroot a -> FilePath -> IO ClockTime # vRaiseError :: HVFSChroot a -> IOErrorType -> String -> Maybe FilePath -> IO c # vCreateSymbolicLink :: HVFSChroot a -> FilePath -> FilePath -> IO () # vReadSymbolicLink :: HVFSChroot a -> FilePath -> IO FilePath # vCreateLink :: HVFSChroot a -> FilePath -> FilePath -> IO () #
HVFS a => HVFS (HVFSReadOnly a) # |
Methods vGetCurrentDirectory :: HVFSReadOnly a -> IO FilePath # vSetCurrentDirectory :: HVFSReadOnly a -> FilePath -> IO () # vGetDirectoryContents :: HVFSReadOnly a -> FilePath -> IO [FilePath] # vDoesFileExist :: HVFSReadOnly a -> FilePath -> IO Bool # vDoesDirectoryExist :: HVFSReadOnly a -> FilePath -> IO Bool # vDoesExist :: HVFSReadOnly a -> FilePath -> IO Bool # vCreateDirectory :: HVFSReadOnly a -> FilePath -> IO () # vRemoveDirectory :: HVFSReadOnly a -> FilePath -> IO () # vRenameDirectory :: HVFSReadOnly a -> FilePath -> FilePath -> IO () # vRemoveFile :: HVFSReadOnly a -> FilePath -> IO () # vRenameFile :: HVFSReadOnly a -> FilePath -> FilePath -> IO () # vGetFileStatus :: HVFSReadOnly a -> FilePath -> IO HVFSStatEncap # vGetSymbolicLinkStatus :: HVFSReadOnly a -> FilePath -> IO HVFSStatEncap # vGetModificationTime :: HVFSReadOnly a -> FilePath -> IO ClockTime # vRaiseError :: HVFSReadOnly a -> IOErrorType -> String -> Maybe FilePath -> IO c # vCreateSymbolicLink :: HVFSReadOnly a -> FilePath -> FilePath -> IO () # vReadSymbolicLink :: HVFSReadOnly a -> FilePath -> IO FilePath # vCreateLink :: HVFSReadOnly a -> FilePath -> FilePath -> IO () #

class Show a => HVFSStat a where #

Evaluating types of files and information about them.

This corresponds to the System.Posix.Types.FileStatus type, and indeed, that is one instance of this class.

Inplementators must, at minimum, implement `vIsDirectory` and `vIsRegularFile`.

Default implementations of everything else are provided, returning reasonable values.

A default implementation of this is not currently present on Windows.

Minimal complete definition

vIsRegularFile, vIsDirectory

Methods

vDeviceID :: a -> DeviceID #

vFileID :: a -> FileID #

vFileMode :: a -> FileMode #

Refers to file permissions, NOT the st_mode field from stat(2)

vLinkCount :: a -> LinkCount #

vFileOwner :: a -> UserID #

vFileGroup :: a -> GroupID #

vSpecialDeviceID :: a -> DeviceID #

vFileSize :: a -> FileOffset #

vAccessTime :: a -> EpochTime #

vModificationTime :: a -> EpochTime #

vStatusChangeTime :: a -> EpochTime #

vIsBlockDevice :: a -> Bool #

vIsCharacterDevice :: a -> Bool #

vIsNamedPipe :: a -> Bool #

vIsRegularFile :: a -> Bool #

vIsDirectory :: a -> Bool #

vIsSymbolicLink :: a -> Bool #

vIsSocket :: a -> Bool #

Instances

HVFSStat FileStatus # |
Methods vDeviceID :: FileStatus -> DeviceID # vFileID :: FileStatus -> FileID # vFileMode :: FileStatus -> FileMode # vLinkCount :: FileStatus -> LinkCount # vFileOwner :: FileStatus -> UserID # vFileGroup :: FileStatus -> GroupID # vSpecialDeviceID :: FileStatus -> DeviceID # vFileSize :: FileStatus -> FileOffset # vAccessTime :: FileStatus -> EpochTime # vModificationTime :: FileStatus -> EpochTime # vStatusChangeTime :: FileStatus -> EpochTime # vIsBlockDevice :: FileStatus -> Bool # vIsCharacterDevice :: FileStatus -> Bool # vIsNamedPipe :: FileStatus -> Bool # vIsRegularFile :: FileStatus -> Bool # vIsDirectory :: FileStatus -> Bool # vIsSymbolicLink :: FileStatus -> Bool # vIsSocket :: FileStatus -> Bool #
HVFSStat SimpleStat # |
Methods vDeviceID :: SimpleStat -> DeviceID # vFileID :: SimpleStat -> FileID # vFileMode :: SimpleStat -> FileMode # vLinkCount :: SimpleStat -> LinkCount # vFileOwner :: SimpleStat -> UserID # vFileGroup :: SimpleStat -> GroupID # vSpecialDeviceID :: SimpleStat -> DeviceID # vFileSize :: SimpleStat -> FileOffset # vAccessTime :: SimpleStat -> EpochTime # vModificationTime :: SimpleStat -> EpochTime # vStatusChangeTime :: SimpleStat -> EpochTime # vIsBlockDevice :: SimpleStat -> Bool # vIsCharacterDevice :: SimpleStat -> Bool # vIsNamedPipe :: SimpleStat -> Bool # vIsRegularFile :: SimpleStat -> Bool # vIsDirectory :: SimpleStat -> Bool # vIsSymbolicLink :: SimpleStat -> Bool # vIsSocket :: SimpleStat -> Bool #

class HVFS a => HVFSOpenable a where #

Types that can open a HVIO object should be instances of this class. You need only implement `vOpen`.

Minimal complete definition

vOpen

Methods

vOpen :: a -> FilePath -> IOMode -> IO HVFSOpenEncap #

vReadFile :: a -> FilePath -> IO String #

vWriteFile :: a -> FilePath -> String -> IO () #

vOpenBinaryFile :: a -> FilePath -> IOMode -> IO HVFSOpenEncap #

Instances

HVFSOpenable SystemFS # |
Methods vOpen :: SystemFS -> FilePath -> IOMode -> IO HVFSOpenEncap # vReadFile :: SystemFS -> FilePath -> IO String # vWriteFile :: SystemFS -> FilePath -> String -> IO () # vOpenBinaryFile :: SystemFS -> FilePath -> IOMode -> IO HVFSOpenEncap #
HVFSOpenable MemoryVFS # |
Methods vOpen :: MemoryVFS -> FilePath -> IOMode -> IO HVFSOpenEncap # vReadFile :: MemoryVFS -> FilePath -> IO String # vWriteFile :: MemoryVFS -> FilePath -> String -> IO () # vOpenBinaryFile :: MemoryVFS -> FilePath -> IOMode -> IO HVFSOpenEncap #
HVFSOpenable a => HVFSOpenable (HVFSChroot a) # |
Methods vOpen :: HVFSChroot a -> FilePath -> IOMode -> IO HVFSOpenEncap # vReadFile :: HVFSChroot a -> FilePath -> IO String # vWriteFile :: HVFSChroot a -> FilePath -> String -> IO () # vOpenBinaryFile :: HVFSChroot a -> FilePath -> IOMode -> IO HVFSOpenEncap #
HVFSOpenable a => HVFSOpenable (HVFSReadOnly a) # |
Methods vOpen :: HVFSReadOnly a -> FilePath -> IOMode -> IO HVFSOpenEncap # vReadFile :: HVFSReadOnly a -> FilePath -> IO String # vWriteFile :: HVFSReadOnly a -> FilePath -> String -> IO () # vOpenBinaryFile :: HVFSReadOnly a -> FilePath -> IOMode -> IO HVFSOpenEncap #

data HVFSOpenEncap #

Similar to `HVFSStatEncap`, but for `vOpen` result.

Constructors

HVIO a => HVFSOpenEncap a |

data HVFSStatEncap #

Encapsulate a `HVFSStat` result. This is required due to Haskell typing restrictions. You can get at it with:

    case encap of
       HVFSStatEncap x -> -- now use x

Constructors

HVFSStat a => HVFSStatEncap a |

withStat :: forall b. HVFSStatEncap -> (forall a. HVFSStat a => a -> b) -> b #

Convenience function for working with stat -- takes a stat result and a function that uses it, and returns the result.

Here is an example from the HVFS source:

       vGetModificationTime fs fp =
          do s <- vGetFileStatus fs fp
             return $ epochToClockTime (withStat s vModificationTime)

See `epochToClockTime` for more information.

withOpen :: forall b. HVFSOpenEncap -> (forall a. HVIO a => a -> b) -> b #

Similar to `withStat`, but for the `vOpen` result.

data SystemFS #

Constructors

SystemFS |

Instances

Eq SystemFS # |
Methods (==) :: SystemFS -> SystemFS -> Bool # (/=) :: SystemFS -> SystemFS -> Bool #
Show SystemFS # |
Methods showsPrec :: Int -> SystemFS -> ShowS # show :: SystemFS -> String # showList :: [SystemFS] -> ShowS #
HVFSOpenable SystemFS # |
Methods vOpen :: SystemFS -> FilePath -> IOMode -> IO HVFSOpenEncap # vReadFile :: SystemFS -> FilePath -> IO String # vWriteFile :: SystemFS -> FilePath -> String -> IO () # vOpenBinaryFile :: SystemFS -> FilePath -> IOMode -> IO HVFSOpenEncap #
HVFS SystemFS # |
Methods vGetCurrentDirectory :: SystemFS -> IO FilePath # vSetCurrentDirectory :: SystemFS -> FilePath -> IO () # vGetDirectoryContents :: SystemFS -> FilePath -> IO [FilePath] # vDoesFileExist :: SystemFS -> FilePath -> IO Bool # vDoesDirectoryExist :: SystemFS -> FilePath -> IO Bool # vDoesExist :: SystemFS -> FilePath -> IO Bool # vCreateDirectory :: SystemFS -> FilePath -> IO () # vRemoveDirectory :: SystemFS -> FilePath -> IO () # vRenameDirectory :: SystemFS -> FilePath -> FilePath -> IO () # vRemoveFile :: SystemFS -> FilePath -> IO () # vRenameFile :: SystemFS -> FilePath -> FilePath -> IO () # vGetFileStatus :: SystemFS -> FilePath -> IO HVFSStatEncap # vGetSymbolicLinkStatus :: SystemFS -> FilePath -> IO HVFSStatEncap # vGetModificationTime :: SystemFS -> FilePath -> IO ClockTime # vRaiseError :: SystemFS -> IOErrorType -> String -> Maybe FilePath -> IO c # vCreateSymbolicLink :: SystemFS -> FilePath -> FilePath -> IO () # vReadSymbolicLink :: SystemFS -> FilePath -> IO FilePath # vCreateLink :: SystemFS -> FilePath -> FilePath -> IO () #

# Re-exported types from other modules

type FilePath = String #

File and directory names are values of type `String`, whose precise meaning is operating system dependent. Files can be opened, yielding a handle which can then be used to operate on the contents of that file.

type DeviceID = CDev #

type FileID = CIno #

type FileMode = CMode #

type LinkCount = CNlink #

type UserID = CUid #

type GroupID = CGid #

type FileOffset = COff #

type EpochTime = CTime #

data IOMode :: * #

See `openFile`

Instances

Enum IOMode |
Methods succ :: IOMode -> IOMode # pred :: IOMode -> IOMode # toEnum :: Int -> IOMode # fromEnum :: IOMode -> Int # enumFrom :: IOMode -> [IOMode] # enumFromThen :: IOMode -> IOMode -> [IOMode] # enumFromTo :: IOMode -> IOMode -> [IOMode] # enumFromThenTo :: IOMode -> IOMode -> IOMode -> [IOMode] #
Eq IOMode |
Methods (==) :: IOMode -> IOMode -> Bool # (/=) :: IOMode -> IOMode -> Bool #
Ord IOMode |
Methods compare :: IOMode -> IOMode -> Ordering # (<) :: IOMode -> IOMode -> Bool # (<=) :: IOMode -> IOMode -> Bool # (>) :: IOMode -> IOMode -> Bool # (>=) :: IOMode -> IOMode -> Bool # max :: IOMode -> IOMode -> IOMode # min :: IOMode -> IOMode -> IOMode #
Read IOMode |
Methods readsPrec :: Int -> ReadS IOMode # readList :: ReadS [IOMode] # readPrec :: ReadPrec IOMode # readListPrec :: ReadPrec [IOMode] #
Show IOMode |
Methods showsPrec :: Int -> IOMode -> ShowS # show :: IOMode -> String # showList :: [IOMode] -> ShowS #
Ix IOMode |
Methods range :: (IOMode, IOMode) -> [IOMode] # index :: (IOMode, IOMode) -> IOMode -> Int # unsafeIndex :: (IOMode, IOMode) -> IOMode -> Int inRange :: (IOMode, IOMode) -> IOMode -> Bool # rangeSize :: (IOMode, IOMode) -> Int # unsafeRangeSize :: (IOMode, IOMode) -> Int

# Orphan instances

Show FileStatus # |
Methods showsPrec :: Int -> FileStatus -> ShowS # show :: FileStatus -> String # showList :: [FileStatus] -> ShowS #