package metadb

  1. Overview
  2. Docs

Make a Metadb database

Parameters

module D : Metadata
module LD : LibData

Signature

Library configuration

val load_config : Path.root -> unit

Load database configurations from file

val write_config : ?ord:string list -> Path.root -> unit

Write database configuration to file. Optional argument is ordering in which libraries should be written

Managing libraries

val new_library : library:string -> Path.root -> LD.t -> unit

Create a new library with name library pointing to the given path

val remove_library : delete_metadata:bool -> library:string -> unit

Remove the given library. If delete_metadata is true, the .metadata directory will be deleted as well.

val rename_library : library:string -> string -> unit

Rename the given library

val move_library : library:string -> Path.root -> unit

Move library to a new path and migrate all files and entries. Raises DirNotEmpty if new directory is not empty

Initializing and refreshing libraries

val init_library : library:string -> unit

Initialize a specific library. This loads existing entries and adds a new entry for every new file without entry

val init_libraries : unit -> unit

Initialize all libraries

val refresh_library : library:string -> (Path.rel * D.t) Seq.t

Refresh a specific library. This adds a new entry for every new file without entry

Reading and modifying data

val get_libdata : unit -> (string * LD.t) list

Get all libraries and their associated metadata

val get_library_root : library:string -> Path.root

Returns root path of specified library

val get_entries : library:string -> (Path.rel * D.t) Seq.t

Get all entries of a specified library and their associated metadata

val get_entry : library:string -> Path.rel -> D.t option

If it exists, get the value of an entry in the specified library. The key to an entry is the relative path of the file with respect to the library's root

val set_entry : library:string -> Path.rel -> D.t -> unit

Set the value of an entry in the specified library. Raises EntryDoesNotExist if key does not exist

val remove_entry : library:string -> Path.rel -> unit

Remove an entry from a specified library, but leave the file

val remove_file : library:string -> Path.rel -> unit

Remove a file from a specified library, but leave the entry

val migrate_entry : from_lib:string -> to_lib:string -> Path.rel -> unit

Move entry and file from one library to another. Raises

Missing and duplicate files

val index_files : unit -> unit

Needed in order to quickly resolve missing files or find duplicates. This should only be called after freshly initializing or refreshing a library

type resolution =
  1. | Remap of Path.rel * (string * Path.rel)
  2. | Missing of Path.rel

Return type of resolve_missing_files.

  • Remap (key, (library',key')) signifies that entry key has been moved to library' with new key key'
  • Missing key signifies that no file could be associated with entry key
val resolve_missing_files : library:string -> resolution Seq.t

Attempt to resolve entries that are no longer pointing to a file. For each entry no longer pointing to a file, this function searches accross all libraries for a file with matching hash. If an entry to the corresponding file exists, attempt to merge both entries. This function assumes

Note: Library metadata should be flushed after calling this function to prevent data loss

val find_duplicates : unit -> (string * Path.rel) list list

Return a partition of the duplicate files, of the form:

[[(lib_11, file_11), (lib_12, file_12),...]
 [(lib_21, file_21), (lib_22, file_22),...]
 ...
 [(lib_n1, file_n1), (lib_n2, file_n2),...]]

such that entries in each row are duplicate files having the same hash. This function assumes

This may be called immediately after resolve_missing_files

Writing data to disk

val flush_library_metadata : library:string -> unit

Write modified metadata for specified library to disk

val flush_metadata : unit -> unit

Flush metadata for all libraries

Debugging

val library_to_string : library:string -> string

Flush entire library to a string, for debugging purposes

OCaml

Innovation. Community. Security.