Virtfs.TreeSourceDescribes a file tree containing files or directories (a directory being a file tree). Unlike Path, which can be used in an application to abstract paths, Tree is mainly used to mount virtual file systems, which are particularly useful for writing unit tests.
The tree module is quite rigid and imposes the File vs Directory structure, but makes no assumptions whatsoever about the contents of files and the metadata associated with files and directories.
Describes a tree (a directory or file list).
A tree is a list of items, where an item can be a file or a directory (which is a list of files).
Describes the contents of a file system, which may be files or directories.
Building a tree generally involves lifting a list of items.
val make :
?scope_metadata:(Path.t -> 'metadata option) ->
scope:Path.t ->
('a, 'metadata) Item.t list ->
('a, 'metadata) tmake ?scope_metadata ?scope items builds a tree. The scope parameter allows you to define the tree in a given path. The scope_metadata function allows you to attach metadata to each intermediate directory in the scope.
val dir :
?metadata:'metadata ->
name:string ->
('a, 'metadata) Item.t list ->
('a, 'metadata) Item.tSee Item.dir
fetch ~path fs try to reach the item at the position path.
prism fs scope returns a sub-tree based on a path (scope).
val update :
path:Path.t ->
(previous:('a, 'metadata) Item.t option ->
path:Path.t ->
('a, 'metadata) Item.t option) ->
('a, 'metadata) t ->
('a, 'metadata) tupdate ~path callback fs generic function to modify the filetree, it is the callback function (returning an option) that describes whether the file should be created or deleted.
val touch :
path:Path.t ->
?if_exists:(('a, 'metadata) Item.t -> ('a, 'metadata) Item.t) ->
?metadata:'metadata ->
'a ->
('a, 'metadata) t ->
('a, 'metadata) ttouch ~path ?metadata content fs returns a new filesystem where, if the target exists, if_exists is applied; otherwise, a file is created.
rm ~path fs remove the item by a given path.
rm_file ~path fs remove the file by a given path.
rm_dir ~path fs remove the directory by a given path.
mv fs ~target ~source move source as target. If the target exists, or the given source does not exists, fs remains unchanged.
As the purpose of the virtual file system is primarily for testing, the API provides a collection of inspection tools.
ls fs returns a flat list of strings, equivalent to applying the Unix ls command.
tree fs returns a character string that prints the given tree fs in tree form, similar to the tree command (in Unix).
cat ~to_string fs path Returns a string that resembles the output of the cat command in Unix (without concatenation).
The implementation is not abstract, which allows generic functions to be used on a Simple tree (mostly used for tests).