diff --git a/sys_util/src/file_sync.rs b/sys_util/src/file_traits.rs similarity index 57% rename from sys_util/src/file_sync.rs rename to sys_util/src/file_traits.rs index a67be056e0..2dfc28d50d 100644 --- a/sys_util/src/file_sync.rs +++ b/sys_util/src/file_traits.rs @@ -19,3 +19,19 @@ impl FileSync for File { self.sync_all() } } + +/// A trait for setting the size of a file. +/// This is equivalent to File's `set_len` method, but +/// wrapped in a trait so that it can be implemented for +/// other types. +pub trait FileSetLen { + // Set the size of this file. + // This is the moral equivalent of `ftruncate()`. + fn set_len(&self, _len: u64) -> Result<()>; +} + +impl FileSetLen for File { + fn set_len(&self, len: u64) -> Result<()> { + File::set_len(self, len) + } +} diff --git a/sys_util/src/lib.rs b/sys_util/src/lib.rs index 38fa81fc23..185489c00f 100644 --- a/sys_util/src/lib.rs +++ b/sys_util/src/lib.rs @@ -21,7 +21,7 @@ pub mod syslog; mod errno; mod eventfd; mod file_flags; -mod file_sync; +mod file_traits; mod fork; mod guest_address; mod guest_memory; @@ -62,7 +62,7 @@ pub use tempdir::*; pub use terminal::*; pub use timerfd::*; -pub use file_sync::FileSync; +pub use file_traits::{FileSetLen, FileSync}; pub use guest_memory::Error as GuestMemoryError; pub use mmap::Error as MmapError; pub use seek_hole::SeekHole;