Skip to main content

base_scheduler/
file_sync.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use super::FileOperation;
5use crate::{Cancellation, OperationResult, SyncMode};
6use std::future::Future;
7
8/// Synchronize file contents and metadata through the chosen scheduler.
9pub trait FileSync: FileOperation {
10    /// Synchronize file contents and selected metadata, waiting for OS completion and reporting errors. This leaves the shared cursor unchanged. Await preceding writes first; this call does not order concurrent operations or flush application buffers.
11    ///
12    /// The future is lazy. Cancellation before dispatch prevents submission; blocking workers check again before execution. Once submitted, cancellation is best effort, and a successful completion wins a concurrent cancellation request. Dropping the future cannot undo synchronization; the backend retains the file until access ends.
13    ///
14    /// Durability follows the platform, filesystem, and device guarantees. `SyncMode::Data` may perform full synchronization. Synchronizing a file does not synchronize its parent directory entry.
15    fn file_sync(
16        &self,
17        file: &Self::File,
18        mode: SyncMode,
19        cancellation: &Cancellation,
20    ) -> impl Future<Output = OperationResult<()>> + Send;
21}