mirror of https://github.com/sharkdp/fd.git
maint: Remove use of unmaintained users crate
The users crate is no longer maintained. There is a maintained fork called uzers, but we already have a dependency on nix, and that has the functionality we need.
This commit is contained in:
parent
8f32a758a4
commit
054bae01ef
|
@ -317,7 +317,6 @@ dependencies = [
|
||||||
"regex-syntax 0.7.5",
|
"regex-syntax 0.7.5",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"test-case",
|
"test-case",
|
||||||
"users",
|
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -792,16 +791,6 @@ version = "1.0.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "users"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8parse"
|
name = "utf8parse"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
|
|
@ -66,8 +66,7 @@ default-features = false
|
||||||
features = ["nu-ansi-term"]
|
features = ["nu-ansi-term"]
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
users = "0.11.0"
|
nix = { version = "0.26.2", default-features = false, features = ["signal", "user"] }
|
||||||
nix = { version = "0.26.2", default-features = false, features = ["signal"] }
|
|
||||||
|
|
||||||
[target.'cfg(all(unix, not(target_os = "redox")))'.dependencies]
|
[target.'cfg(all(unix, not(target_os = "redox")))'.dependencies]
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
use nix::unistd::{Group, User};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
@ -35,16 +36,22 @@ impl OwnerFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
let uid = Check::parse(fst, |s| {
|
let uid = Check::parse(fst, |s| {
|
||||||
s.parse()
|
if let Ok(uid) = s.parse() {
|
||||||
.ok()
|
Ok(uid)
|
||||||
.or_else(|| users::get_user_by_name(s).map(|user| user.uid()))
|
} else {
|
||||||
.ok_or_else(|| anyhow!("'{}' is not a recognized user name", s))
|
User::from_name(s)?
|
||||||
|
.map(|user| user.uid.as_raw())
|
||||||
|
.ok_or_else(|| anyhow!("'{}' is not a recognized user name", s))
|
||||||
|
}
|
||||||
})?;
|
})?;
|
||||||
let gid = Check::parse(snd, |s| {
|
let gid = Check::parse(snd, |s| {
|
||||||
s.parse()
|
if let Ok(gid) = s.parse() {
|
||||||
.ok()
|
Ok(gid)
|
||||||
.or_else(|| users::get_group_by_name(s).map(|group| group.gid()))
|
} else {
|
||||||
.ok_or_else(|| anyhow!("'{}' is not a recognized group name", s))
|
Group::from_name(s)?
|
||||||
|
.map(|group| group.gid.as_raw())
|
||||||
|
.ok_or_else(|| anyhow!("'{}' is not a recognized group name", s))
|
||||||
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(OwnerFilter { uid, gid })
|
Ok(OwnerFilter { uid, gid })
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
mod testenv;
|
mod testenv;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
use nix::unistd::{Gid, Group, Uid, User};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -1302,7 +1304,7 @@ fn test_type_executable() {
|
||||||
// This test assumes the current user isn't root
|
// This test assumes the current user isn't root
|
||||||
// (otherwise if the executable bit is set for any level, it is executable for the current
|
// (otherwise if the executable bit is set for any level, it is executable for the current
|
||||||
// user)
|
// user)
|
||||||
if users::get_current_uid() == 0 {
|
if Uid::current().is_root() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2261,10 +2263,10 @@ fn test_owner_ignore_all() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_owner_current_user() {
|
fn test_owner_current_user() {
|
||||||
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
let uid = users::get_current_uid();
|
let uid = Uid::current();
|
||||||
te.assert_output(&["--owner", &uid.to_string(), "a.foo"], "a.foo");
|
te.assert_output(&["--owner", &uid.to_string(), "a.foo"], "a.foo");
|
||||||
if let Some(username) = users::get_current_username().map(|u| u.into_string().unwrap()) {
|
if let Ok(Some(user)) = User::from_uid(uid) {
|
||||||
te.assert_output(&["--owner", &username, "a.foo"], "a.foo");
|
te.assert_output(&["--owner", &user.name, "a.foo"], "a.foo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2272,10 +2274,10 @@ fn test_owner_current_user() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_owner_current_group() {
|
fn test_owner_current_group() {
|
||||||
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
let gid = users::get_current_gid();
|
let gid = Gid::current();
|
||||||
te.assert_output(&["--owner", &format!(":{}", gid), "a.foo"], "a.foo");
|
te.assert_output(&["--owner", &format!(":{}", gid), "a.foo"], "a.foo");
|
||||||
if let Some(groupname) = users::get_current_groupname().map(|u| u.into_string().unwrap()) {
|
if let Ok(Some(group)) = Group::from_gid(gid) {
|
||||||
te.assert_output(&["--owner", &format!(":{}", groupname), "a.foo"], "a.foo");
|
te.assert_output(&["--owner", &format!(":{}", group.name), "a.foo"], "a.foo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2283,7 +2285,7 @@ fn test_owner_current_group() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_owner_root() {
|
fn test_owner_root() {
|
||||||
// This test assumes the current user isn't root
|
// This test assumes the current user isn't root
|
||||||
if users::get_current_uid() == 0 || users::get_current_gid() == 0 {
|
if Uid::current().is_root() || Gid::current() == Gid::from_raw(0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
|
||||||
|
|
Loading…
Reference in New Issue