base_scheduler/file_truncate.rs
1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use super::FileOperation;
5use crate::{Cancellation, OperationResult};
6use std::future::Future;
7
8/// Change the logical length of an already-open file resource.
9pub trait FileTruncate: FileOperation {
10 /// Set the logical file length, discarding bytes when shrinking and filling an extension with zeros. The file must be open for writing. Lengths must fit in `i64`; filesystem limits and other OS errors are reported. The shared cursor is unchanged, even when it ends up past EOF.
11 ///
12 /// The future is lazy. Cancellation before dispatch prevents submission; blocking workers check again before execution. Once submitted, cancellation is best effort and successful completion wins a concurrent request. The backend retains the file until access ends, and dropping a waiter cannot undo a completed resize.
13 ///
14 /// Await reads, writes, seeks, and truncation sequentially when ordering matters. This operation does not guarantee disk-space reservation or durability; use `file_sync` after completion when synchronization is needed.
15 fn file_truncate(
16 &self,
17 file: &Self::File,
18 length: u64,
19 cancellation: &Cancellation,
20 ) -> impl Future<Output = OperationResult<()>> + Send;
21}