Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-stdx/src/faccess.rs')
-rw-r--r--helix-stdx/src/faccess.rs62
1 files changed, 10 insertions, 52 deletions
diff --git a/helix-stdx/src/faccess.rs b/helix-stdx/src/faccess.rs
index b98ae153..0270c1f8 100644
--- a/helix-stdx/src/faccess.rs
+++ b/helix-stdx/src/faccess.rs
@@ -1,4 +1,3 @@
-//! Functions for managine file metadata.
//! From <https://github.com/Freaky/faccess>
use std::io;
@@ -52,8 +51,8 @@ mod imp {
}
fn chown(p: &Path, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
- let uid = uid.map(rustix::fs::Uid::from_raw);
- let gid = gid.map(rustix::fs::Gid::from_raw);
+ let uid = uid.map(|n| unsafe { rustix::fs::Uid::from_raw(n) });
+ let gid = gid.map(|n| unsafe { rustix::fs::Gid::from_raw(n) });
rustix::fs::chown(p, uid, gid)?;
Ok(())
}
@@ -71,32 +70,17 @@ mod imp {
perms.set_mode(new_perms);
}
- #[cfg(target_os = "macos")]
- {
- use std::fs::{File, FileTimes};
- use std::os::macos::fs::FileTimesExt;
-
- let to_file = File::options().write(true).open(to)?;
- let times = FileTimes::new().set_created(from_meta.created()?);
- to_file.set_times(times)?;
- }
-
std::fs::set_permissions(to, perms)?;
Ok(())
}
-
- pub fn hardlink_count(p: &Path) -> std::io::Result<u64> {
- let metadata = p.metadata()?;
- Ok(metadata.nlink())
- }
}
// Licensed under MIT from faccess except for `chown`, `copy_metadata` and `is_acl_inherited`
#[cfg(windows)]
mod imp {
- use windows_sys::Win32::Foundation::{CloseHandle, LocalFree, ERROR_SUCCESS, HANDLE};
+ use windows_sys::Win32::Foundation::{CloseHandle, LocalFree, ERROR_SUCCESS, HANDLE, PSID};
use windows_sys::Win32::Security::Authorization::{
GetNamedSecurityInfoW, SetNamedSecurityInfoW, SE_FILE_OBJECT,
};
@@ -106,12 +90,12 @@ mod imp {
SecurityImpersonation, ACCESS_ALLOWED_CALLBACK_ACE, ACL, ACL_SIZE_INFORMATION,
DACL_SECURITY_INFORMATION, GENERIC_MAPPING, GROUP_SECURITY_INFORMATION, INHERITED_ACE,
LABEL_SECURITY_INFORMATION, OBJECT_SECURITY_INFORMATION, OWNER_SECURITY_INFORMATION,
- PRIVILEGE_SET, PROTECTED_DACL_SECURITY_INFORMATION, PSECURITY_DESCRIPTOR, PSID,
+ PRIVILEGE_SET, PROTECTED_DACL_SECURITY_INFORMATION, PSECURITY_DESCRIPTOR,
SID_IDENTIFIER_AUTHORITY, TOKEN_DUPLICATE, TOKEN_QUERY,
};
use windows_sys::Win32::Storage::FileSystem::{
- GetFileInformationByHandle, BY_HANDLE_FILE_INFORMATION, FILE_ACCESS_RIGHTS,
- FILE_ALL_ACCESS, FILE_GENERIC_EXECUTE, FILE_GENERIC_READ, FILE_GENERIC_WRITE,
+ FILE_ACCESS_RIGHTS, FILE_ALL_ACCESS, FILE_GENERIC_EXECUTE, FILE_GENERIC_READ,
+ FILE_GENERIC_WRITE,
};
use windows_sys::Win32::System::Threading::{GetCurrentThread, OpenThreadToken};
@@ -119,13 +103,7 @@ mod imp {
use std::ffi::c_void;
- use std::os::windows::{
- ffi::OsStrExt,
- fs::{FileTimesExt, OpenOptionsExt},
- io::AsRawHandle,
- };
-
- use std::fs::{File, FileTimes};
+ use std::os::windows::{ffi::OsStrExt, fs::OpenOptionsExt};
struct SecurityDescriptor {
sd: PSECURITY_DESCRIPTOR,
@@ -312,21 +290,21 @@ mod imp {
let mut privileges_length = std::mem::size_of::<PRIVILEGE_SET>() as u32;
let mut result = 0;
- let mapping = GENERIC_MAPPING {
+ let mut mapping = GENERIC_MAPPING {
GenericRead: FILE_GENERIC_READ,
GenericWrite: FILE_GENERIC_WRITE,
GenericExecute: FILE_GENERIC_EXECUTE,
GenericAll: FILE_ALL_ACCESS,
};
- unsafe { MapGenericMask(&mut mode, &mapping) };
+ unsafe { MapGenericMask(&mut mode, &mut mapping) };
if unsafe {
AccessCheck(
*sd.descriptor(),
*token.as_handle(),
mode,
- &mapping,
+ &mut mapping,
&mut privileges,
&mut privileges_length,
&mut granted_access,
@@ -429,26 +407,10 @@ mod imp {
let meta = std::fs::metadata(from)?;
let perms = meta.permissions();
- let to_file = File::options().write(true).open(to)?;
- let times = FileTimes::new().set_created(meta.created()?);
- to_file.set_times(times)?;
-
std::fs::set_permissions(to, perms)?;
Ok(())
}
-
- pub fn hardlink_count(p: &Path) -> std::io::Result<u64> {
- let file = std::fs::File::open(p)?;
- let handle = file.as_raw_handle();
- let mut info: BY_HANDLE_FILE_INFORMATION = unsafe { std::mem::zeroed() };
-
- if unsafe { GetFileInformationByHandle(handle, &mut info) } == 0 {
- Err(std::io::Error::last_os_error())
- } else {
- Ok(info.nNumberOfLinks as u64)
- }
- }
}
// Licensed under MIT from faccess except for `copy_metadata`
@@ -495,7 +457,3 @@ pub fn readonly(p: &Path) -> bool {
pub fn copy_metadata(from: &Path, to: &Path) -> io::Result<()> {
imp::copy_metadata(from, to)
}
-
-pub fn hardlink_count(p: &Path) -> io::Result<u64> {
- imp::hardlink_count(p)
-}