Modulefs-sim-0.5.0.1Haskell2010
System.FS.Sim.MockFS
Mock file system implementation
Intended for qualified import
import System.FS.Sim.MockFS (MockFS)
import qualified System.FS.Sim.MockFS as Mock- 7 types
- 31 values
- Packagefs-sim-0.5.0.1
- Exports38
- LanguageHaskell2010
- LicenceApache-2.0
- SourceMockFS.hs
Return True iff the handle is open.
Throws an exception if the handle is unknown.
Number of open handles
Renders the MockFS in a human-readable fashion.
Debugging
1 declarationOperations on files
9 declarationsMock implementation of hClose
Get file size
NOTE: In the mock implementation this is thread safe, because there can be only one writer, so concurrent threads cannot change the size of the file.
Get bytes from handle
NOTE: Unlike real I/O, we disallow hGetSome on a handle in append mode.
Thread safe version of hGetSome, which doesn't modify or read the file offset.
Mock implementation of hIsOpen
Mock implementation of hOpen.
NOTE: Differences from Posix:
We do not support opening directories.
We do not support more than one concurrent writer (we do however allow a writer and multiple concurrent readers)
We do not support create file on ReadMode.
Mock implementation of hSeek
NOTE: This is more restricted than the IO version, because seek has some odd properties:
We do not allow seeking at all on files in append mode
We do not allow seeking past the end of the file (this means that when using
IO.SeekFromEnd, the only valid offset is 0)We do not return the new file offset
Truncate a file
NOTE: Differences from Posix:
Although this corresponds to Posix
ftruncate, this can only be used to make files smaller, not larger.We only support this in append mode. The reason is that Posix
ftruncatedoes not modify the file offset, and adds padding with zeroes on subsequent writes. This is however not behaviour we want to emulate. In append mode however the Posix file offset is not used (and we don't even record it at all), appends always happen at the end of the file.
Operations on directories
8 declarationsCheck if directory exists
It seems real I/O maps what would be "inapproriate device" errors to False.
Check if file exists
See comments for doesDirectoryExist.
Remove a directory and its contents
Same limitations as removeFile.
Remove a file
The behaviour of unlink is to remove the file after all open file handles
that refer to it are closed. The open file handles referring to the file
can still be used to write/read to/from, while at the same time, the file
is invisible for all other operations.
We do not implement this behaviour and consider this a limitation of the mock file system, and throw an error when removing a file that still has open file handles to it.
In the state machine tests, removing the root directory may cause the IO implementation to throw an FsInsufficientPermissions error, depending on the permissions of the temporary directory used to run the tests in. In theory it should throw a FsResourceInappropriateType error. To avoid this mismatch during testing, we also consider removing the root folder a limitation of the mock file system.
Exported for the benefit of tests only
2 declarationsWe store the files as an FsTree of the file contents
opaque
Instances3Show, Generic, Rep
Show ClosedHandleStateDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFSGeneric ClosedHandleStateDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFStype Rep ClosedHandleState = D1 ('MetaDataDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFS"ClosedHandleState"
"System.FS.Sim.MockFS"
"fs-sim-0.5.0.1-AMG23qT3NTsFrMOedWsD8M"
'False) (C1 ('MetaCons"ClosedHandle"
'PrefixI 'True) (S1 ('MetaSel ('Just"closedFilePath"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FsPath)))
File pointer
This is purely an internal abstraction.
Instances3Show, Generic, Rep
Show FilePtrDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFSGeneric FilePtrDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFStype Rep FilePtr = D1 ('MetaDataDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFS"FilePtr"
"System.FS.Sim.MockFS"
"fs-sim-0.5.0.1-AMG23qT3NTsFrMOedWsD8M"
'False) (C1 ('MetaCons"RW"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool) :*: (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Word64))) :+: C1 ('MetaCons"Append"
'PrefixI 'False) U1)
Mock handle internal state
Instances3Show, Generic, Rep
Show HandleStateDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFSGeneric HandleStateDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFStype Rep HandleState = D1 ('MetaDataDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFS"HandleState"
"System.FS.Sim.MockFS"
"fs-sim-0.5.0.1-AMG23qT3NTsFrMOedWsD8M"
'False) (C1 ('MetaCons"HandleOpen"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 OpenHandleState)) :+: C1 ('MetaCons"HandleClosed"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 ClosedHandleState)))
Instances3Show, Generic, Rep
Show OpenHandleStateDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFSGeneric OpenHandleStateDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFStype Rep OpenHandleState = D1 ('MetaDataDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFS"OpenHandleState"
"System.FS.Sim.MockFS"
"fs-sim-0.5.0.1-AMG23qT3NTsFrMOedWsD8M"
'False) (C1 ('MetaCons"OpenHandle"
'PrefixI 'True) (S1 ('MetaSel ('Just"openFilePath"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FsPath) :*: S1 ('MetaSel ('Just"openPtr"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 FilePtr)))
opaque
2 declarationsA mock handle to a file on disk.
This is only meaningful when interpreted against a MockFS.
Instances6Enum, Eq, Ord, Show, Generic, Rep
Enum HandleMockDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFSEq HandleMockDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFSOrd HandleMockDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFSShow HandleMockDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFSGeneric HandleMockDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFStype Rep HandleMock = D1 ('MetaDataDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFS"HandleMock"
"System.FS.Sim.MockFS"
"fs-sim-0.5.0.1-AMG23qT3NTsFrMOedWsD8M"
'True) (C1 ('MetaCons"HandleMock"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))
Instances4Show, Generic, MonadState, Rep
Show MockFSDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFSGeneric MockFSDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFSMonad m => MonadState MockFS (FSSimT m)Defined in fs-sim-0.5.0.1 · System.FS.Sim.Primtype Rep MockFS = D1 ('MetaDataDefined in fs-sim-0.5.0.1 · System.FS.Sim.MockFS"MockFS"
"System.FS.Sim.MockFS"
"fs-sim-0.5.0.1-AMG23qT3NTsFrMOedWsD8M"
'False) (C1 ('MetaCons"MockFS"
'PrefixI 'True) (S1 ('MetaSel ('Just"mockFiles"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Files) :*: (S1 ('MetaSel ('Just"mockHandles"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Map HandleMock HandleState)) :*: S1 ('MetaSel ('Just"mockNextHandle"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 HandleMock))))