pub async fn sync_dir(path: impl AsRef<Path>) -> Result<()>Expand description
Writes the entries of the directory at path through to the device: the
names created, removed or renamed in it before the call survive a crash.
A file’s own sync_all does not cover its name in the directory, so the
name needs this call. It runs on the blocking pool.
To replace a file target atomically, so a crash leaves either the old
contents or the new and never a mix:
- write the new contents to a temporary file in the same directory,
sync_allthe temporary file,renameit overtarget,sync_dirthe directory they are in.
On Windows the directory is opened with backup semantics for reading and
writing and flushed (FlushFileBuffers); on Apple’s systems a full flush
of a directory the system refuses is made with fsync.
§Errors
The system’s own: path does not exist, cannot be opened, or is not
something the system lets be synced. A path that is not a directory gets
the answer the system gives for it.