1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

tests: add AtPath.set_mode() method

Add the `AtPath.set_mode()` method that sets the permissions for a
given path in the test directory.
This commit is contained in:
Jeffrey Finkelstein 2022-09-23 17:42:35 -04:00
parent fba8d495d2
commit 2f88ba8628

View file

@ -19,7 +19,7 @@ use std::ffi::OsStr;
use std::fs::{self, hard_link, File, OpenOptions};
use std::io::{BufWriter, Read, Result, Write};
#[cfg(unix)]
use std::os::unix::fs::{symlink as symlink_dir, symlink as symlink_file};
use std::os::unix::fs::{symlink as symlink_dir, symlink as symlink_file, PermissionsExt};
#[cfg(windows)]
use std::os::windows::fs::{symlink_dir, symlink_file};
#[cfg(windows)]
@ -821,6 +821,20 @@ impl AtPath {
s
}
}
/// Set the permissions of the specified file.
///
/// # Panics
///
/// This function panics if there is an error loading the metadata
/// or setting the permissions of the file.
#[cfg(not(windows))]
pub fn set_mode(&self, filename: &str, mode: u32) {
let path = self.plus(filename);
let mut perms = std::fs::metadata(&path).unwrap().permissions();
perms.set_mode(mode);
std::fs::set_permissions(&path, perms).unwrap();
}
}
/// An environment for running a single uutils test case, serves three functions: