Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file fs_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2020,2021 DaiLambda, Inc. <contact@dailambda.jp> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)moduletypeNAME=sig(** Type of file and directory names *)typetvalequal:t->t->boolvalto_string:t->stringvalpp:Format.formatter->t->unitvalto_segment:t->Segment.tvalof_segment:Segment.t->toptionvaltest:string->unitendmoduletypePATH=sigtypename(** Path, a list of names *)typet=namelist(** Length of the names of a path *)vallength:t->intvalequal:t->t->boolvalto_string:t->stringvalpp:Format.formatter->t->unitvalto_segments:t->Segment.tlistvalof_segments:Segment.tlist->toption(** [is_prefix_of p1 p2] checks [p1] is a prefix of [p2].
If it is, it returns [Some p2'] such that [p1 @ p2' = p2].
Otherwise it returns [None].
*)valis_prefix_of:t->t->toptionend(** File system over Plebeia tree.
Here, a `cursor` is a zipper over a Plebeia tree.
*)moduletypeS=sig(** Type of file name *)typename(** Path name, a list of names *)modulePath:PATHwithtypename=name(** Type for the underlying cursor *)typeraw_cursor(** type for the pointer to a directory/file *)typecursor(** Type of Plebeia tree of a file or a directory *)typeview(** Hash of a file or a directory *)typehash(** Errors. The first parameter is the name of the failed API function *)typeerror=|Is_fileofstring*Path.t|Is_directoryofstring*Path.t|No_such_file_or_directoryofstring*Path.t|File_or_directory_existsofstring*Path.t|Path_decode_failureofSegment.t|Otherofstring*stringtypeError.t+=FS_erroroferror(** [make raw_cursor path] wraps [raw_cursor] which points to [path]
and returns a cursor *)valmake:raw_cursor->Path.t->cursor(** [empty context] returns a cursor pointing the empty file system *)valempty:Context.t->cursor(** Returns the underlying context of the given cursor *)valcontext:cursor->Context.t(** Get the underlying cursor *)valget_raw_cursor:cursor->raw_cursormoduleOp:sig(** Monad for synchronous file system operations *)type'at=cursor->(cursor*'a,Error.t)resultincludeMonad.S1withtype'at:='atvallift_result:('a,Error.t)Result.t->'at(** Fail with the given error *)valfail:error->'at(** Get the current underlying cursor *)valraw_cursor:raw_cursort(** Moves the cursor up 1 directory level.
If the cursor is already at the root, it does nothing. *)valchdir_parent:unitt(** Moves the cursor up to the root directory.
If the cursor is already at the root, it does nothing. *)valchdir_root:unitt(** Moves the cursor to a sub-directory specified by the path.
If [dig=true], subdirectories are created if necessary. *)valchdir:?dig:bool->Path.t->unitt(** Get the current path of the cursor *)valpath:Path.tt(** File and directory access. It returns the current cursor and its view.
*)valget:Path.t->(cursor*view)t(** [set path cursor] sets the tree pointed by the [cursor]
at the specified path.
The path must not be empty. *)valset:Path.t->cursor->unitt(** [copy src dst] sets the tree at [src] to [dst].
[dst] must not be empty. *)valcopy:Path.t->Path.t->unitt(** Regular file read access. *)valcat:Path.t->Value.tt(** Create or update a regular file. Directories are created if necessary.
The path must not be empty. *)valwrite:Path.t->Value.t->unitt(** Remove a regular file or a directory, then returns [Ok true].
The path must not be empty.
recursive=false : fails when the target is a directory
recursive=true : removes the target recursively if it is a directory
ignore_error=false : fails when the target does not exist
ignore_error=true : does not fail even if the target does not exist
Returns [true] if the target is really removed.
Returns [false] if the target does not exist.
*)valrm:?recursive:bool->?ignore_error:bool->Path.t->boolt(** Recursive removal of a directory
The path must not be empty.
ignore_error=false : fails when the target does not exist
ignore_error=true : does not fail even if the target does not exist
Returns [true] if the target is really removed.
Returns [false] if the target does not exist.
*)valrmdir:?ignore_error:bool->Path.t->boolt(** Compute the Merkle hash of the cursor *)valcompute_hash:hasht(** Clear the memory cache of the tree under the current cursor,
if it is already persisted on the disk.
*)valmay_forget:unitt(** Monad runner *)valrun:cursor->'at->(cursor*'a,Error.t)result(** For debugging. [do_then f op] executes [f] against the current cursor,
then performs [op]. *)valdo_then:(cursor->unit)->'at->'atendmoduleOp_lwt:sig(** Monad for asynchronous file system operations *)type'at=cursor->(cursor*'a,Error.t)resultLwt.tincludeMonad.S1withtype'at:='at(** Convert Op monad to Op_lwt *)vallift:'aOp.t->'atvallift_op:'aOp.t->'atvallift_lwt:'aLwt.t->'atvallift_result:('a,Error.t)Result.t->'atvallift_result_lwt:('a,Error.t)Result_lwt.t->'at(** Fail with the given error *)valfail:error->'at(** Get the current underlying cursor *)valraw_cursor:raw_cursort(** Moves the cursor up 1 directory level.
If the cursor is already at the root, it does nothing. *)valchdir_parent:unitt(** Moves the cursor up to the root directory.
If the cursor is already at the root, it does nothing. *)valchdir_root:unitt(** Moves the cursor to a sub-directory specified by the path.
If [dig=true], subdirectories are created if necessary. *)valchdir:?dig:bool->Path.t->unitt(** Get the current path of the cursor *)valpath:Path.tt(** File and directory access. It returns the current cursor and its view.
*)valget:Path.t->(cursor*view)t(** Set the tree pointed by the [cursor] at the specified path.
The path must not be empty.
Note: there is no loop detection. It is the user's responsibility
not to introduce a loop by this function. *)valset:Path.t->cursor->unitt(** [copy src dst] sets the tree at [src] to [dst].
[dst] must not be empty.
If the copy creates a loop, the function fails. *)valcopy:Path.t->Path.t->unitt(** Regular file read access. *)valcat:Path.t->Value.tt(** Create or update a regular file. Directories are created if necessary.
The path must not be empty.
*)valwrite:Path.t->Value.t->unitt(** Remove a regular file or a directory, then returns [Ok true].
The path must not be empty.
recursive=false : fails when the target is a directory
recursive=true : removes the target recursively if it is a directory
ignore_error=false : fails when the target does not exist
ignore_error=true : does not fail even if the target does not exist
Returns [true] if the target is really removed.
Returns [false] if the target does not exist.
*)valrm:?recursive:bool->?ignore_error:bool->Path.t->boolt(** Recursive removal of a directory
The path must not be empty.
ignore_error=false : fails when the target does not exist
ignore_error=true : does not fail even if the target does not exist
Returns [true] if the target is really removed.
Returns [false] if the target does not exist.
*)valrmdir:?ignore_error:bool->Path.t->boolt(** Compute the Merkle hash of the cursor *)valcompute_hash:hasht(** Clear the memory cache of the tree under the current cursor,
if it is already persisted on the disk.
*)valmay_forget:unitt(** [do_then f op] executes [f] against the current cursor,
then performs [op]. *)valdo_then:(cursor->unit)->'at->'at(** Monad runner *)valrun:cursor->'at->(cursor*'a,Error.t)resultLwt.t(** folding
- `Continue: if the item is a directory, its items are recursively folded
- `Up: if the item is a directory, its items are skipped
- `Exit: terminate the folding immediately and returns the accumulator
as the final result of [fold]
*)valfold:'a->Path.t->('a->Path.t->cursor->([`Continue|`Exit|`Up]*'a,Error.t)resultLwt.t)->'at(** folding with a depth specification *)valfold':?depth:[`Eqofint|`Geofint|`Gtofint|`Leofint|`Ltofint]->'a->Path.t->('a->Path.t->cursor->('a,Error.t)resultLwt.t)->'at(** List the directory specified by the path *)valls:Path.t->(name*cursor)listtend(** Version control *)moduleVc:sig(** Type of version controller *)typet=Vc.t(** Create an empty commit store *)valcreate:?hashcons:Hashcons.config->?node_cache:Index.tNode_cache.t->?lock:bool->?bytes_per_cell:int->?hash_func:[`Blake2B|`Blake3]->?bytes_per_hash:int->?resize_step_bytes:int->?auto_flush_seconds:int->string->(t,Error.t)Result_lwt.t(** Opens a commit store of the given name if it exists.
Otherwise, it creates a new store. *)valopen_:mode:Storage.mode->?hashcons:Hashcons.config->?node_cache:Index.tNode_cache.t->?bytes_per_cell:int->?hash_func:[`Blake2B|`Blake3]->?bytes_per_hash:int->?resize_step_bytes:int->?auto_flush_seconds:int->string->(t,Error.t)Result_lwt.t(** Close the version control.
Once closed, further uses of [t] are unspecified. *)valclose:t->(unit,Error.t)resultLwt.t(** Returns a cursor pointing to an empty tree *)valempty:t->cursor(** Returns a cursor pointing to a leaf with the value specified
by the given bytes *)valof_value:t->bytes->cursor(** Checkout the commit of the given commit hash *)valcheckout:t->Commit_hash.t->cursoroptionLwt.t(** Same as [checkout] but returns the commit information together *)valcheckout':t->Commit_hash.t->(Commit.t*cursor)optionLwt.t(** Check the given commit hash is known *)valmem:t->Commit_hash.t->boolLwt.t(** Compute the commit hash for the root of the current tree.
The cursor is moved to the root.
Note that the commit hash is NOT the top Merkle hash of the cursor.
It is computed from the top Merkle hash and the parent commit hash
*)valcompute_commit_hash:t->parent:Commit_hash.toption->cursor->cursor*Commit_hash.t(** Commit the contents of the cursor at the root.
It then returns the updated cursor, the hash,
and the commit information.
If [override] is [false] (by default), hash collision fails
the function. If it is [true], it overwrites the hash.
The commit will be persisted to the disk eventually, but may be
lost if the program crashes. To make it surely persisted,
[sync] must be called explicitly.
*)valcommit:?allow_missing_parent:bool->t->parent:Commit_hash.toption->hash_override:Commit_hash.toption->(Hash.Prefix.t*Commit.t)Op_lwt.t(** Synchronize the commits to the disk. Commits after the last call of
this [flush] may be lost when the program crashes.
Too frequent call of this function may slow down the system.
*)valflush:t->unitLwt.t(** Underlying commit database *)valcommit_db:t->Commit_db.t(** Underlying context *)valcontext:t->Context.tendmoduleMerkle_proof:sigtypet=Merkle_proof.ttypedetail=Path.t*Segment.segmentlist*Node_type.nodeoptionvalencoding:Vc.t->tData_encoding.tvalpp:Format.formatter->t->unit(** Build a Merkle proof of the given paths under the current cursor.
It also returns the objects at the paths.
*)valmake:Path.tlist->(t*detaillist)Op.t(** Compute the top hash of the given Merkle proof. It also returns
the objects at the paths attached with the proof.
*)valcheck:Vc.t->t->(Hash.Prefix.t*detaillist,Error.t)resultendend