Skip to main content

sync_dir

Function sync_dir 

Source
pub fn sync_dir(dir: &Path) -> Result<()>
Expand description

Flushes dir’s own metadata, making renames into it durable.

Call it after the rename that installs a staged file, not before: it is the directory entry created by that rename that needs to reach the disk. Callers that skip it keep the atomicity guarantee (a reader sees the old file or the new one, never a fragment) and lose only the durability one, and only to a power cut.

§Platforms

Unix only. On Windows this is a no-op that answers Ok without touching dir, so a rename there is as durable as NTFS makes it and no more. Callers get the same API on both and a weaker guarantee on one.

§Errors

  • std::io::Error when dir could not be opened, or when flushing it failed for a reason the filesystem could act on. EINVAL is not one of them: it reads as “this filesystem has no such step” and the write stands. Never returns an error on Windows.