• Per Cederqvist's avatar
    Write dbfiles atomically, renaming them once complete. · 50e88538
    Per Cederqvist authored
    Added support for renaming a datafile once it has been completely
    written, and to write it using a temporary extension.
    * src/server/ram-io.h (struct dbfile): Added fields fn,
    tmp_extension and tmp_fn.  Added documentation.
    (dbfile_open_write): New argument: tmp_extension.
    (dbfile_rename): New function.
    (dbfile_abort): New function.
    * src/server/ram-io.c (dbfile_new): Initialize fn, tmp_extension
    and tmp_fn.
    (current_fn): New static function.  Return tmp_fn if non-NULL,
    otherwise fn.
    (dbfile_delete): Free the new fields fn, tmp_extension and
    (dbfile_open_write): New argument: tmp_extension.  Store a copy of
    the supplied filename.  If tmp_extension is non-NULL, store a copy
    of it, and compute the actual file name to open as the filname
    followed by the tmp_extension.
    (fsync_dirname): New static function.
    (dbfile_rename): New function.  Rename the file from tmp_fn to the
    wanted final filename, and sync the directory.
    (dbfile_abort): New function.
    * src/server/dbck-cache.c (cache_sync_all): Pass a NULL pointer as
    tmp_extension of dbfile_open_write(), to get the old behavior.
    * src/server/simple-cache.c (pre_sync): Ditto.
.topdeps 8 Bytes