Fsync a directory to ensure file creation/deletion metadata is durable. On ext4/XFS, creating or deleting a file writes the file data to disk but the directory entry may only be in the page cache. A power loss before the directory entry is persisted causes the file to "disappear" on reboot. Calling fsync on the directory fd ensures the metadata (filename, inode pointer) is on stable storage.
(dir: &Path)
| 32 | /// on reboot. Calling fsync on the directory fd ensures the metadata |
| 33 | /// (filename, inode pointer) is on stable storage. |
| 34 | pub fn fsync_directory(dir: &Path) -> Result<()> { |
| 35 | let dir_file = fs::File::open(dir).map_err(WalError::Io)?; |
| 36 | dir_file.sync_all().map_err(WalError::Io)?; |
| 37 | Ok(()) |
| 38 | } |
| 39 | |
| 40 | /// Atomically write `bytes` to `dst` via a `tmp` file with full durability. |
| 41 | /// |
no test coverage detected