From c6cccff92e898cd6e98b5cc4659456aaceab0097 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 10 Jul 2024 16:39:43 +0200 Subject: [PATCH] sys: remove deprecations Signed-off-by: Wolfgang Bumiller --- proxmox-sys/src/{fd/mod.rs => fd.rs} | 9 -- proxmox-sys/src/fd/borrowed_fd.rs | 40 -------- proxmox-sys/src/fd/fd_impl.rs | 134 --------------------------- proxmox-sys/src/fd/raw_fd_num.rs | 57 ------------ proxmox-sys/src/fs/xattr.rs | 21 ----- proxmox-sys/src/lib.rs | 9 +- proxmox-sys/src/linux/tty.rs | 12 --- 7 files changed, 3 insertions(+), 279 deletions(-) rename proxmox-sys/src/{fd/mod.rs => fd.rs} (91%) delete mode 100644 proxmox-sys/src/fd/borrowed_fd.rs delete mode 100644 proxmox-sys/src/fd/fd_impl.rs delete mode 100644 proxmox-sys/src/fd/raw_fd_num.rs diff --git a/proxmox-sys/src/fd/mod.rs b/proxmox-sys/src/fd.rs similarity index 91% rename from proxmox-sys/src/fd/mod.rs rename to proxmox-sys/src/fd.rs index f005b6ab..ad12e663 100644 --- a/proxmox-sys/src/fd/mod.rs +++ b/proxmox-sys/src/fd.rs @@ -6,15 +6,6 @@ use nix::fcntl::OFlag; use nix::sys::stat::Mode; use nix::NixPath; -mod fd_impl; -pub use fd_impl::*; - -mod raw_fd_num; -pub use raw_fd_num::*; - -mod borrowed_fd; -pub use borrowed_fd::*; - use std::os::unix::io::{FromRawFd, OwnedFd, RawFd}; use nix::fcntl::{fcntl, FdFlag, F_GETFD, F_SETFD}; diff --git a/proxmox-sys/src/fd/borrowed_fd.rs b/proxmox-sys/src/fd/borrowed_fd.rs deleted file mode 100644 index 11f823aa..00000000 --- a/proxmox-sys/src/fd/borrowed_fd.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![allow(deprecated)] - -use std::marker::PhantomData; -use std::os::unix::io::{AsRawFd, RawFd}; - -/// A borrowed file raw descriptor. (A `RawFd` with an attached lifetime). -/// -/// For when using `&FdRef` is not an option. -/// -/// This specifically does not implement `IntoRawFd` or `FromRawFd`, since those would drop life -/// times. -#[derive(Debug, Eq, PartialEq)] -#[deprecated(note = "use std::os::unix::io::BorrowedFd instead")] -pub struct BorrowedFd<'a> { - fd: RawFd, - _borrow: PhantomData<&'a RawFd>, -} - -impl<'a> BorrowedFd<'a> { - #[inline] - pub fn new(fd: &T) -> Self { - Self { - fd: fd.as_raw_fd(), - _borrow: PhantomData, - } - } -} - -impl AsRawFd for BorrowedFd<'_> { - fn as_raw_fd(&self) -> RawFd { - self.fd - } -} - -impl<'a, T: ?Sized + AsRawFd> From<&'a T> for BorrowedFd<'a> { - #[inline] - fn from(fd: &'a T) -> Self { - Self::new(fd) - } -} diff --git a/proxmox-sys/src/fd/fd_impl.rs b/proxmox-sys/src/fd/fd_impl.rs deleted file mode 100644 index d4732c80..00000000 --- a/proxmox-sys/src/fd/fd_impl.rs +++ /dev/null @@ -1,134 +0,0 @@ -use std::borrow::Borrow; -use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; - -use nix::fcntl::OFlag; -use nix::sys::stat::Mode; -use nix::NixPath; - -/// Guard a raw file descriptor with a drop handler. This is mostly useful when access to an owned -/// `RawFd` is required without the corresponding handler object (such as when only the file -/// descriptor number is required in a closure which may be dropped instead of being executed). -#[derive(Debug)] -#[deprecated(note = "use std::os::unix::io::OwnedFd instead")] -pub struct Fd(pub RawFd); - -#[allow(deprecated)] -impl Drop for Fd { - fn drop(&mut self) { - // `>= 0` instead of `!= -1` to also handle things like AT_FDCWD - if self.0 >= 0 { - unsafe { - libc::close(self.0); - } - } - } -} - -#[allow(deprecated)] -impl Fd { - #[deprecated(note = "use proxmox_sys::fd::cwd instead")] - pub const fn cwd() -> Self { - Self(libc::AT_FDCWD) - } - - #[deprecated(note = "use proxmox_sys::fd::open instead")] - pub fn open

(path: &P, oflag: OFlag, mode: Mode) -> Result - where - P: ?Sized + NixPath, - { - nix::fcntl::open(path, oflag, mode).map(Self) - } - - #[deprecated(note = "use proxmox_sys::fd::openat instead")] - pub fn openat(dirfd: &D, path: &P, oflag: OFlag, mode: Mode) -> Result - where - D: AsRawFd, - P: ?Sized + NixPath, - { - nix::fcntl::openat(dirfd.as_raw_fd(), path, oflag, mode).map(Self) - } - - /// Borrow this file descriptor as an `&FdRef`. - pub fn as_fd_ref(&self) -> &FdRef { - unsafe { &*(&self.0 as *const RawFd as *const FdRef) } - } -} - -#[allow(deprecated)] -impl FromRawFd for Fd { - unsafe fn from_raw_fd(fd: RawFd) -> Self { - Self(fd) - } -} - -#[allow(deprecated)] -impl AsRawFd for Fd { - fn as_raw_fd(&self) -> RawFd { - self.0 - } -} - -#[allow(deprecated)] -impl IntoRawFd for Fd { - fn into_raw_fd(mut self) -> RawFd { - let fd = self.0; - self.0 = -1; - fd - } -} - -#[allow(deprecated)] -impl AsRef for Fd { - fn as_ref(&self) -> &FdRef { - self.as_fd_ref() - } -} - -#[allow(deprecated)] -impl Borrow for Fd { - fn borrow(&self) -> &FdRef { - self.as_fd_ref() - } -} - -#[allow(deprecated)] -impl std::ops::Deref for Fd { - type Target = FdRef; - - fn deref(&self) -> &FdRef { - self.as_fd_ref() - } -} - -#[allow(deprecated)] -impl From for Fd { - fn from(fd: OwnedFd) -> Fd { - Fd(fd.into_raw_fd()) - } -} - -#[allow(deprecated)] -impl From for OwnedFd { - fn from(fd: Fd) -> OwnedFd { - unsafe { OwnedFd::from_raw_fd(fd.into_raw_fd()) } - } -} - -/// A reference to a raw file descriptor. (Strongly typed `&RawFd` which is not equivalent to an -/// `&i32`. -/// -/// `RawFd` should only be used as parameter type for functions, but never as a return type, since -/// it is not clear whether the returned integer is borrowed or owned. Instead, functions should -/// return `Fd` or `&FdRef`. -/// -/// This specifically does not implement `IntoRawFd` or `FromRawFd`, since those would drop life -/// times. -#[derive(Debug, Eq, PartialEq)] -pub enum FdRef {} - -impl AsRawFd for FdRef { - #[inline] - fn as_raw_fd(&self) -> RawFd { - unsafe { *(self as *const Self as *const RawFd) } - } -} diff --git a/proxmox-sys/src/fd/raw_fd_num.rs b/proxmox-sys/src/fd/raw_fd_num.rs deleted file mode 100644 index c98bce39..00000000 --- a/proxmox-sys/src/fd/raw_fd_num.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![allow(deprecated)] - -use std::borrow::Borrow; -use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; - -use super::FdRef; - -/// Raw file descriptor by number. Thin wrapper to provide `AsRawFd` which a simple `RawFd` does -/// not since it's just an `i32`. -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -#[deprecated(note = "use OwnedFd, &OwnedFd, BorrowedFd or just &RawFd instead")] -pub struct RawFdNum(RawFd); - -impl RawFdNum { - /// Borrow this file descriptor as an `&FdRef`. - pub fn as_fd_ref(&self) -> &FdRef { - unsafe { &*(&self.0 as *const RawFd as *const FdRef) } - } -} - -impl AsRawFd for RawFdNum { - fn as_raw_fd(&self) -> RawFd { - self.0 - } -} - -impl FromRawFd for RawFdNum { - unsafe fn from_raw_fd(fd: RawFd) -> Self { - Self(fd) - } -} - -impl IntoRawFd for RawFdNum { - fn into_raw_fd(self) -> RawFd { - self.0 - } -} - -impl AsRef for RawFdNum { - fn as_ref(&self) -> &FdRef { - self.as_fd_ref() - } -} - -impl Borrow for RawFdNum { - fn borrow(&self) -> &FdRef { - self.as_fd_ref() - } -} - -impl std::ops::Deref for RawFdNum { - type Target = FdRef; - - fn deref(&self) -> &FdRef { - self.as_fd_ref() - } -} diff --git a/proxmox-sys/src/fs/xattr.rs b/proxmox-sys/src/fs/xattr.rs index 209da514..6d85dcd4 100644 --- a/proxmox-sys/src/fs/xattr.rs +++ b/proxmox-sys/src/fs/xattr.rs @@ -10,33 +10,12 @@ use proxmox_io::vec; /// `"security.capability"` as a CStr to avoid typos. pub const XATTR_NAME_FCAPS: &CStr = c"security.capability"; -/// `"security.capability"` as a CStr to avoid typos. -#[deprecated = "use the XATTR_NAME_FCAPS constant instead"] -#[inline] -pub const fn xattr_name_fcaps() -> &'static CStr { - XATTR_NAME_FCAPS -} - /// `"system.posix_acl_access"` as a CStr to avoid typos. pub const XATTR_ACL_ACCESS: &CStr = c"system.posix_acl_access"; -/// `"system.posix_acl_access"` as a CStr to avoid typos. -#[deprecated = "use the XATTR_ACL_ACCESS constant instead"] -#[inline] -pub const fn xattr_acl_access() -> &'static CStr { - XATTR_ACL_ACCESS -} - /// `"system.posix_acl_default"` as a CStr to avoid typos. pub const XATTR_ACL_DEFAULT: &CStr = c"system.posix_acl_default"; -/// `"system.posix_acl_default"` as a CStr to avoid typos. -#[deprecated = "use the XATTR_ACL_DEFAULT constant instead"] -#[inline] -pub const fn xattr_acl_default() -> &'static CStr { - XATTR_ACL_DEFAULT -} - /// Result of `flistxattr`, allows iterating over the attributes as a list of `&CStr`s. /// /// Listing xattrs produces a list separated by zeroes, inherently making them available as `&CStr` diff --git a/proxmox-sys/src/lib.rs b/proxmox-sys/src/lib.rs index 02fcfc59..de6fafba 100644 --- a/proxmox-sys/src/lib.rs +++ b/proxmox-sys/src/lib.rs @@ -1,5 +1,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +use std::os::fd::{FromRawFd, OwnedFd}; use std::os::unix::ffi::OsStrExt; pub mod boot_mode; @@ -21,9 +22,6 @@ pub mod systemd; mod worker_task_context; pub use worker_task_context::*; -#[allow(deprecated)] -use fd::Fd; - /// Returns the hosts node name (UTS node name) pub fn nodename() -> &'static str { lazy_static::lazy_static! { @@ -47,8 +45,7 @@ pub fn nodename() -> &'static str { /// Safe wrapper for `nix::unistd::pipe2` defaulting to `O_CLOEXEC` /// and guarding the file descriptors. -#[allow(deprecated)] -pub fn pipe() -> Result<(Fd, Fd), nix::Error> { +pub fn pipe() -> Result<(OwnedFd, OwnedFd), nix::Error> { let (pin, pout) = nix::unistd::pipe2(nix::fcntl::OFlag::O_CLOEXEC)?; - Ok((Fd(pin), Fd(pout))) + Ok(unsafe { (OwnedFd::from_raw_fd(pin), OwnedFd::from_raw_fd(pout)) }) } diff --git a/proxmox-sys/src/linux/tty.rs b/proxmox-sys/src/linux/tty.rs index 9a1e4679..d08ae81f 100644 --- a/proxmox-sys/src/linux/tty.rs +++ b/proxmox-sys/src/linux/tty.rs @@ -25,18 +25,6 @@ pub fn stdout_terminal_size() -> (usize, usize) { (winsize.ws_row as usize, winsize.ws_col as usize) } -/// Returns whether the current stdout is a tty. -#[deprecated(note = "Use std::io::stdout().is_terminal()")] -pub fn stdout_isatty() -> bool { - std::io::stdout().is_terminal() -} - -/// Returns whether the current stdin is a tty. -#[deprecated(note = "Use std::io::stdin().is_terminal()")] -pub fn stdin_isatty() -> bool { - std::io::stdin().is_terminal() -} - pub enum TtyOutput { Stdout(std::io::Stdout), DevTty(OwnedFd),