yaml
Adapters call read and write rather than touching yaml_serde and
the filesystem directly so that the file-format choice and the on-disk
invariants (atomic write, parent-directory creation, trailing newline) live
in exactly one place.
Stable, human-readable output is the responsibility of the wrapper structs
the adapters define: yaml_serde honors struct field declaration order,
so listing fields in a fixed sequence is enough to keep diffs clean.
fn read
pub fn read<T: DeserializeOwned>(path: &Path) -> Result<Option<T>, Error>Read and YAML-deserialize a file into T, returning Ok(None) if absent.
Any other I/O or parse error is propagated. Adapters use this to walk a directory and skip vanished files without paying special attention to race conditions.
| Parameter | Type | Description |
|---|---|---|
path |
&Path | the YAML file to read |
| returns | Result<Option<T>, Error> | The parsed value. |
fn write_cached
pub async fn write_cached<T: Serialize>(
conn: &Connection,
project_id: &Id,
gest_dir: &Path,
path: &Path,
value: &T,
) -> Result<(), Error>Serialize value, write it to path, and update the sync_digests cache.
If the cached digest for (project_id, relative_to(path)) already matches
the new content, the file is left untouched and the cache is unchanged.
This is the standard write path for every per-entity sync adapter.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection that holds the sync_digests cache |
project_id |
&Id | the project that owns the file |
gest_dir |
&Path | the project’s .gest/ directory, which path must be inside |
path |
&Path | the file to write; missing parent directories are created |
value |
&T | the entity’s serializable wrapper struct |
| returns | Result<(), Error> | Ok(()) when the file was written or already matched; an error when path is outside gest_dir, or when serializing, writing or the cache query fails. |
fn cleanup_orphans
pub async fn cleanup_orphans(
conn: &Connection,
project_id: &Id,
gest_dir: &Path,
dir: &Path,
extension: &str,
alive_ids: &std::collections::HashSet<String>,
) -> Result<(), Error>Remove every file under dir whose filename stem is not present in
alive_ids, and drop the corresponding sync_digests cache entries.
Each per-entity adapter calls this at the end of its write_all to clean
up files left over from deleted entities. Without it, the next import
would re-insert rows that the user just deleted (because the file is
still on disk).
A file whose YAML has a non-null top-level deleted_at is a tombstone and is kept.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection that holds the sync_digests cache |
project_id |
&Id | the project that owns the files |
gest_dir |
&Path | the project’s .gest/ directory, which dir must be inside |
dir |
&Path | the entity directory to clean, walked recursively |
extension |
&str | the file extension to consider, without the dot, such as yaml |
alive_ids |
&std::collections::HashSet<String> | the ids of the entities that still exist |
| returns | Result<(), Error> | Ok(()) once every orphan is removed, or the first I/O or database error. |
fn is_tombstoned_yaml_file
pub(in crate::store::sync) fn is_tombstoned_yaml_file(path: &Path) -> boolReturn true if the YAML file at path carries a deleted_at tombstone
key at the top level. Parse errors and missing files are treated as “not
tombstoned” so cleanup callers fall back to their normal behavior.
| Parameter | Type | Description |
|---|---|---|
path |
&Path | the YAML file to inspect |
| returns | bool | true only for a YAML mapping whose deleted_at is not null. |
fn walk_files
pub fn walk_files(dir: &Path, extension: &str) -> Result<Vec<PathBuf>, Error>Walk a directory recursively and return every file path matching extension.
| Parameter | Type | Description |
|---|---|---|
dir |
&Path | the directory to walk |
extension |
&str | the file extension to match, without the dot, such as yaml |
| returns | Result<Vec<PathBuf>, Error> | Returns an empty vector if dir does not exist. The walker is depth-first; a missing subdirectory is skipped, but any other read error stops the walk. The paths are sorted. |
fn walk_files_into
fn walk_files_into(dir: &Path, extension: &str, out: &mut Vec<PathBuf>) -> Result<(), Error>Append every file under dir whose extension is extension, recursing into subdirectories.
| Parameter | Type | Description |
|---|---|---|
dir |
&Path | the directory to walk; a missing one adds nothing |
extension |
&str | the file extension to match, without the dot |
out |
&mut Vec<PathBuf> | the list that receives the matching paths, in directory order |
| returns | Result<(), Error> | Ok(()) once the tree is walked, or the first I/O error other than a missing dir. |