AtomicFile
Object Hierarchy:
Description:
public class AtomicFile : Object
Atomic file update helper.
AtomicFile writes data by replacing file contents in a single step, reducing risk of partial writes and corrupted configuration files.
Optional backup support keeps previous contents before replacement.
Example:
var configured = new AtomicFile ()
.withBackup (true)
.backupSuffix (".bak");
assert (configured.isOk ());
var atomic = configured.unwrap ();
bool ok = atomic.write (new Path ("/tmp/app.conf"), "port=8080\n");
Content:
Creation methods:
Methods:
- public bool append (Path path, string text)
Appends text by reading current content and writing merged content
atomically.
- public Result<AtomicFile,Error> backupSuffix (string suffix)
Sets backup suffix used when backup is enabled.
- public string? readConsistent (Path path)
Reads text with basic consistency validation.
- public bool replace (Path srcTmp, Path dst)
Replaces destination with source temporary file.
- public AtomicFile withBackup (bool enabled)
Enables or disables backup creation before replacement.
- public bool write (Path path, string text)
Writes text atomically to the destination path.
- public bool writeBytes (Path path, uint8[] data)
Writes bytes atomically to the destination path.
Inherited Members:
All known members inherited from class GLib.Object
- @get
- @new
- @ref
- @set
- add_toggle_ref
- add_weak_pointer
- bind_property
- connect
- constructed
- disconnect
- dispose
- dup_data
- dup_qdata
- force_floating
- freeze_notify
- get_class
- get_data
- get_property
- get_qdata
- get_type
- getv
- interface_find_property
- interface_install_property
- interface_list_properties
- is_floating
- new_valist
- new_with_properties
- newv
- notify
- notify_property
- ref_count
- ref_sink
- remove_toggle_ref
- remove_weak_pointer
- replace_data
- replace_qdata
- set_data
- set_data_full
- set_property
- set_qdata
- set_qdata_full
- set_valist
- setv
- steal_data
- steal_qdata
- thaw_notify
- unref
- watch_closure
- weak_ref
- weak_unref