mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-12-25 04:14:06 +00:00
sys_util: add set_len() trait
Generalize file_sync into file_traits so that we can add another wrapper, this time for the set_len() method implemented directly on File. This will also be implemented on QcowFile. BUG=chromium:858815 TEST=build_test Change-Id: I43fbd1968a844c8cac359973a63babcc26942204 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1394148 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
parent
d1eceeca7b
commit
6d47e1b005
2 changed files with 18 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue