package virtfs

  1. Overview
  2. Docs

Module Tree.Simple

A truly very naive implementation of a file system where the contents of files are strings and their metadata only associates modification dates.

The API throws Simple_error exceptions to mimic Unix behaviour.

Types

type time = float

The float type is used to represent time, in the same way as the Unix module.

type 'a clock = 'a -> time

A clock is simply a function that produces a value of type time.

type metadata

The metadata type is deliberately left abstract to simplify its potential extension.

type content = string

The contents of the files are simple strings.

type nonrec item = (content, metadata) Item.t

Items of the file system.

type nonrec t = (content, metadata) t

Items of the file system.

Error handling

The API relies on exceptions to describe failures. Each function that may fail throws the Dummy_tree exception.

type error

Set of all possible errors.

exception Simple_error of error
val error_to_string : error -> string

Render an error as an Unix-like error message.

Tree construction

val const_clock : float -> 'a clock

const_clock f creates a constant clock, always returning f.

val mount : ?clock:Path.t clock -> scope:Path.t -> item list -> t

mount ?clock ~scope children creates a tree using make.

val file : ?clock:(string * content) clock -> name:string -> content -> item

file ?clock ~name content creates a file. The clock is parametrized by the couple of name, content.

val dir : ?clock:string clock -> name:string -> item list -> item

dir ?clock ~name children creates a directory. The clock is parametrized by the name of the directory.

Tree operation

val mtime : path:Path.t -> t -> float

mtime ~path fs returns the modification time of the given item located at the given path.

val file_exists : path:Path.t -> t -> bool
val is_directory : path:Path.t -> t -> bool
val is_file : path:Path.t -> t -> bool
val is_empty_dir : path:Path.t -> t -> bool

is_empty_dir ~path fs returns true if the directory located at path for the given fs is an empty directory.

val mkdir : ?recursive:bool -> ?clock:(content -> time) -> path:Path.t -> t -> t

mkdir ?recursive ?clock ~path creates the directory referenced by the given path with behaviour similar to the Unix command mkdir (the recursive flag is for mkdir -p, default is false).

val rm : ?recursive:bool -> path:Path.t -> t -> t

rm ~path fs remove the item by a given path (like Tree.rm but raising exception).

val rm_file : path:Path.t -> t -> t

rm_file fs path remove the file by a given path (like Tree.rm_file but raising exception).

val rm_dir : ?recursive:bool -> path:Path.t -> t -> t

rm_dir fs path remove the directory by a given path (like Tree.rm_dir but raising exception).

val write_file : ?overwrite:bool -> ?clock:((string * content) -> time) -> path:Path.t -> string -> t -> t

write_file ?overwrite ?clock ~path content fs creates (or overwrites, depending on the overwrite flag, default false) the file path with content content on the given fs.

val read_file : path:Path.t -> t -> string

read_file ~path fs Reads the contents of the file referenced by its path for a given fs.

val read_dir : path:Path.t -> t -> item Path.Map.t

read_dir ~path fs returns the direct children of the directory passed as an argument (in the form of a map of items indexed by Paths).

Misc

val run : ?finalizer:('a -> unit) -> (unit -> 'a) -> unit

run ?finalizer callback runs callback and print errors on stderr.