From c23a457e72abe608715ac76f076f47dc42af07a5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 20:31:44 +0200 Subject: Merging upstream version 1.74.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/rustix/src/fs/abs.rs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'vendor/rustix/src/fs/abs.rs') diff --git a/vendor/rustix/src/fs/abs.rs b/vendor/rustix/src/fs/abs.rs index 81e991772..f57bd00fe 100644 --- a/vendor/rustix/src/fs/abs.rs +++ b/vendor/rustix/src/fs/abs.rs @@ -1,7 +1,6 @@ //! POSIX-style filesystem functions which operate on bare paths. use crate::fd::OwnedFd; -use crate::ffi::{CStr, CString}; #[cfg(not(target_os = "espidf"))] use crate::fs::Access; #[cfg(not(any( @@ -17,9 +16,15 @@ use crate::fs::StatFs; #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] use crate::fs::StatVfs; use crate::fs::{Mode, OFlags, Stat}; -use crate::path::SMALL_PATH_BUFFER_SIZE; +#[cfg(not(target_os = "wasi"))] +use crate::ugid::{Gid, Uid}; use crate::{backend, io, path}; -use alloc::vec::Vec; +#[cfg(feature = "alloc")] +use { + crate::ffi::{CStr, CString}, + crate::path::SMALL_PATH_BUFFER_SIZE, + alloc::vec::Vec, +}; /// `open(path, oflags, mode)`—Opens a file. /// @@ -101,11 +106,13 @@ pub fn lstat(path: P) -> io::Result { /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html /// [Linux]: https://man7.org/linux/man-pages/man2/readlink.2.html +#[cfg(feature = "alloc")] #[inline] pub fn readlink>>(path: P, reuse: B) -> io::Result { path.into_with_c_str(|path| _readlink(path, reuse.into())) } +#[cfg(feature = "alloc")] fn _readlink(path: &CStr, mut buffer: Vec) -> io::Result { // This code would benefit from having a better way to read into // uninitialized memory, but that requires `unsafe`. @@ -170,12 +177,21 @@ pub fn rmdir(path: P) -> io::Result<()> { /// `link(old_path, new_path)`—Creates a hard link. /// +/// POSIX leaves it implementation-defined whether `link` follows a symlink in +/// `old_path`, or creates a new link to the symbolic link itself. On platforms +/// which have it, [`linkat`] avoids this problem since it has an [`AtFlags`] +/// paramter and the [`AtFlags::SYMLINK_FOLLOW`] flag determines whether +/// symlinks should be followed. +/// /// # References /// - [POSIX] /// - [Linux] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html /// [Linux]: https://man7.org/linux/man-pages/man2/link.2.html +/// [`linkat`]: crate::fs::linkat +/// [`AtFlags`]: crate::fs::AtFlags +/// [`AtFlags::SYMLINK_FOLLOW`]: crate::fs::AtFlags::SYMLINK_FOLLOW #[inline] pub fn link(old_path: P, new_path: Q) -> io::Result<()> { old_path.into_with_c_str(|old_path| { @@ -266,3 +282,17 @@ pub fn statfs(path: P) -> io::Result { pub fn statvfs(path: P) -> io::Result { path.into_with_c_str(backend::fs::syscalls::statvfs) } + +/// `chown(path, owner, group)`—Sets open file or directory ownership. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html +/// [Linux]: https://man7.org/linux/man-pages/man2/chown.2.html +#[cfg(not(target_os = "wasi"))] +#[inline] +pub fn chown(path: P, owner: Option, group: Option) -> io::Result<()> { + path.into_with_c_str(|path| backend::fs::syscalls::chown(path, owner, group)) +} -- cgit v1.2.3