mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
test: Implement -k
parser.rs already accepts this, finish the implementation.
This commit is contained in:
parent
439b7e0ca5
commit
d05964a8cb
2 changed files with 26 additions and 0 deletions
|
@ -98,6 +98,7 @@ fn eval(stack: &mut Vec<Symbol>) -> Result<bool, String> {
|
||||||
"-g" => path(&f, PathCondition::GroupIdFlag),
|
"-g" => path(&f, PathCondition::GroupIdFlag),
|
||||||
"-G" => path(&f, PathCondition::GroupOwns),
|
"-G" => path(&f, PathCondition::GroupOwns),
|
||||||
"-h" => path(&f, PathCondition::SymLink),
|
"-h" => path(&f, PathCondition::SymLink),
|
||||||
|
"-k" => path(&f, PathCondition::Sticky),
|
||||||
"-L" => path(&f, PathCondition::SymLink),
|
"-L" => path(&f, PathCondition::SymLink),
|
||||||
"-O" => path(&f, PathCondition::UserOwns),
|
"-O" => path(&f, PathCondition::UserOwns),
|
||||||
"-p" => path(&f, PathCondition::Fifo),
|
"-p" => path(&f, PathCondition::Fifo),
|
||||||
|
@ -170,6 +171,7 @@ enum PathCondition {
|
||||||
GroupIdFlag,
|
GroupIdFlag,
|
||||||
GroupOwns,
|
GroupOwns,
|
||||||
SymLink,
|
SymLink,
|
||||||
|
Sticky,
|
||||||
UserOwns,
|
UserOwns,
|
||||||
Fifo,
|
Fifo,
|
||||||
Readable,
|
Readable,
|
||||||
|
@ -187,6 +189,7 @@ fn path(path: &OsStr, condition: PathCondition) -> bool {
|
||||||
|
|
||||||
const S_ISUID: u32 = 0o4000;
|
const S_ISUID: u32 = 0o4000;
|
||||||
const S_ISGID: u32 = 0o2000;
|
const S_ISGID: u32 = 0o2000;
|
||||||
|
const S_ISVTX: u32 = 0o1000;
|
||||||
|
|
||||||
enum Permission {
|
enum Permission {
|
||||||
Read = 0o4,
|
Read = 0o4,
|
||||||
|
@ -246,6 +249,7 @@ fn path(path: &OsStr, condition: PathCondition) -> bool {
|
||||||
PathCondition::GroupIdFlag => metadata.mode() & S_ISGID != 0,
|
PathCondition::GroupIdFlag => metadata.mode() & S_ISGID != 0,
|
||||||
PathCondition::GroupOwns => metadata.gid() == getegid(),
|
PathCondition::GroupOwns => metadata.gid() == getegid(),
|
||||||
PathCondition::SymLink => metadata.file_type().is_symlink(),
|
PathCondition::SymLink => metadata.file_type().is_symlink(),
|
||||||
|
PathCondition::Sticky => metadata.mode() & S_ISVTX != 0,
|
||||||
PathCondition::UserOwns => metadata.uid() == geteuid(),
|
PathCondition::UserOwns => metadata.uid() == geteuid(),
|
||||||
PathCondition::Fifo => file_type.is_fifo(),
|
PathCondition::Fifo => file_type.is_fifo(),
|
||||||
PathCondition::Readable => perm(metadata, Permission::Read),
|
PathCondition::Readable => perm(metadata, Permission::Read),
|
||||||
|
@ -275,6 +279,7 @@ fn path(path: &OsStr, condition: PathCondition) -> bool {
|
||||||
PathCondition::GroupIdFlag => false,
|
PathCondition::GroupIdFlag => false,
|
||||||
PathCondition::GroupOwns => unimplemented!(),
|
PathCondition::GroupOwns => unimplemented!(),
|
||||||
PathCondition::SymLink => false,
|
PathCondition::SymLink => false,
|
||||||
|
PathCondition::Sticky => false,
|
||||||
PathCondition::UserOwns => unimplemented!(),
|
PathCondition::UserOwns => unimplemented!(),
|
||||||
PathCondition::Fifo => false,
|
PathCondition::Fifo => false,
|
||||||
PathCondition::Readable => false, // TODO
|
PathCondition::Readable => false, // TODO
|
||||||
|
|
|
@ -476,6 +476,27 @@ fn test_nonexistent_file_is_not_symlink() {
|
||||||
.succeeds();
|
.succeeds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(not(windows))] // Windows has no concept of sticky bit
|
||||||
|
fn test_file_is_sticky() {
|
||||||
|
let scenario = TestScenario::new(util_name!());
|
||||||
|
let mut ucmd = scenario.ucmd();
|
||||||
|
let mut chmod = scenario.cmd("chmod");
|
||||||
|
|
||||||
|
scenario.fixtures.touch("sticky_file");
|
||||||
|
chmod.args(&["+t", "sticky_file"]).succeeds();
|
||||||
|
|
||||||
|
ucmd.args(&["-k", "sticky_file"]).succeeds();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_file_is_not_sticky() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-k", "regular_file"])
|
||||||
|
.run()
|
||||||
|
.status_code(1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
fn test_file_owned_by_euid() {
|
fn test_file_owned_by_euid() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue