From 5bb745ec6fc63d0a9bf6dc045780cd897ecb6fdc Mon Sep 17 00:00:00 2001 From: vasilito Date: Mon, 27 Jul 2026 17:05:08 +0900 Subject: [PATCH] libredox: Fd::ftruncate and Fd::futimens take &self, not self POSIX ftruncate(2) and futimens(2) do not close the file descriptor. The previous 'self' (by-value) signature consumed the Fd on call, which would trigger Fd::drop and close the fd as a side effect. After a successful ftruncate the user could no longer use the fd, which is the opposite of the intended semantics. Change to '&self' to match the surrounding methods (fsync, fdatasync both already use &self) and to match POSIX behaviour. The drop-on- failure semantics is preserved by Rust's normal borrow checker: if ftruncate returns Err, the caller's borrow is still valid and the fd stays open. --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e0b097d8c0..018d903bd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -447,11 +447,11 @@ impl Fd { call::fdatasync(self.raw()) } #[inline] - pub fn ftruncate(self, len: usize) -> Result<()> { + pub fn ftruncate(&self, len: usize) -> Result<()> { call::ftruncate(self.raw(), len) } #[inline] - pub fn futimens(self, times: &[data::TimeSpec; 2]) -> Result<()> { + pub fn futimens(&self, times: &[data::TimeSpec; 2]) -> Result<()> { call::futimens(self.raw(), times) } /* TODO: Support unlinkat using std_fs_call