From c137f94977745da0a1ec38aa982ec8938db4db5f Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Thu, 24 Oct 2024 01:03:29 +0200 Subject: [PATCH] Fix port of test code to nix 0.29 to avoid flaky failures --- clircle-handle_ownedfd_for_nix_ge_0_27.diff | 46 ++++++++++++++++----- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/clircle-handle_ownedfd_for_nix_ge_0_27.diff b/clircle-handle_ownedfd_for_nix_ge_0_27.diff index 53c3cac..cc882f4 100644 --- a/clircle-handle_ownedfd_for_nix_ge_0_27.diff +++ b/clircle-handle_ownedfd_for_nix_ge_0_27.diff @@ -1,3 +1,5 @@ +diff --git a/src/clircle_unix.rs b/src/clircle_unix.rs +index 101f208..56448b9 100644 --- a/src/clircle_unix.rs +++ b/src/clircle_unix.rs @@ -4,7 +4,7 @@ use std::convert::TryFrom; @@ -5,11 +7,33 @@ use std::io::{self, Seek}; use std::os::unix::fs::MetadataExt; -use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd}; -+use std::os::unix::io::{AsRawFd,FromRawFd, IntoRawFd, RawFd}; ++use std::os::unix::io::{FromRawFd, IntoRawFd, OwnedFd, RawFd}; use std::{cmp, hash, ops}; /// Re-export of libc -@@ -186,7 +186,7 @@ mod tests { +@@ -53,6 +53,13 @@ impl UnixIdentifier { + ident + }) + } ++ ++ fn try_from_owned_fd(fd: OwnedFd) -> io::Result { ++ Self::try_from(File::from(fd)).map(|mut ident| { ++ ident.owns_fd = true; ++ ident ++ }) ++ } + } + + impl Clircle for UnixIdentifier { +@@ -135,6 +142,7 @@ mod tests { + + use std::error::Error; + use std::io::Write; ++ use std::os::unix::io::AsRawFd; + + use nix::pty::{openpty, OpenptyResult}; + use nix::unistd::close; +@@ -186,7 +194,7 @@ mod tests { #[test] fn test_pty_equal_but_not_conflicting() -> Result<(), &'static str> { let OpenptyResult { master, slave } = openpty(None, None).expect("Could not open pty."); @@ -18,23 +42,25 @@ .map_err(|_| "Error creating UnixIdentifier from pty fd") .and_then(|ident| { if !ident.eq(&ident) { -@@ -196,7 +196,7 @@ mod tests { +@@ -196,7 +204,7 @@ mod tests { return Err("pty fd does not conflict with itself, but conflict detected"); } - let second_ident = unsafe { UnixIdentifier::try_from_raw_fd(slave, false) } -+ let second_ident = unsafe { UnixIdentifier::try_from_raw_fd(slave.as_raw_fd(), false) } ++ let second_ident = UnixIdentifier::try_from_owned_fd(slave) .map_err(|_| "Error creating second Identifier to pty")?; if !ident.eq(&second_ident) { return Err("ident != second_ident"); -@@ -209,8 +209,8 @@ mod tests { +@@ -209,12 +217,6 @@ mod tests { Ok(()) }); - let r1 = close(master); - let r2 = close(slave); -+ let r1 = close(master.as_raw_fd()); -+ let r2 = close(slave.as_raw_fd()); - - r1.expect("Error closing master end of pty"); - r2.expect("Error closing slave end of pty"); +- +- r1.expect("Error closing master end of pty"); +- r2.expect("Error closing slave end of pty"); +- + res + } + }