package core_extended

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Atomically edit a file without long-term locking

See documentation for the function atomic_edit

type return_type =
  1. | Ok
  2. | Changed of string * string
  3. | Abort

the return value of atomic_edit

val atomic_edit : f:(string -> [ `Ok | `Abort ]) -> string -> return_type

atomic_edit ~f filepath edit filepath by making a unique copy (peer) that can be openly changed without holding any locks on the original. When the function returns, a short term exclusive lock is held while overwriting the original with the edited copy. If the mtime of the original is changed since the copy was made, the replacement is aborted (indicating another atomic_edit was first to update the file, or some other process) and Changed is returned with a tuple (warning message * terd file). The terd file contains the edits and might be used to diff or re-edit.

OCaml

Innovation. Community. Security.