mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #3471 from 353fc443/mktemp-set-dir-mode
mktemp: change directory permission after creation
This commit is contained in:
commit
fa577603c2
2 changed files with 25 additions and 0 deletions
|
@ -19,6 +19,11 @@ use std::fmt::Display;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::path::{is_separator, Path, PathBuf, MAIN_SEPARATOR};
|
use std::path::{is_separator, Path, PathBuf, MAIN_SEPARATOR};
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::fs;
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::prelude::PermissionsExt;
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use tempfile::Builder;
|
use tempfile::Builder;
|
||||||
|
|
||||||
|
@ -346,6 +351,11 @@ fn exec(dir: &Path, prefix: &str, rand: usize, suffix: &str, make_dir: bool) ->
|
||||||
.1
|
.1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
if make_dir {
|
||||||
|
fs::set_permissions(&path, fs::Permissions::from_mode(0o700))?;
|
||||||
|
}
|
||||||
|
|
||||||
// Get just the last component of the path to the created
|
// Get just the last component of the path to the created
|
||||||
// temporary file or directory.
|
// temporary file or directory.
|
||||||
let filename = path.file_name();
|
let filename = path.file_name();
|
||||||
|
|
|
@ -7,6 +7,9 @@ use uucore::display::Quotable;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
static TEST_TEMPLATE1: &str = "tempXXXXXX";
|
static TEST_TEMPLATE1: &str = "tempXXXXXX";
|
||||||
static TEST_TEMPLATE2: &str = "temp";
|
static TEST_TEMPLATE2: &str = "temp";
|
||||||
static TEST_TEMPLATE3: &str = "tempX";
|
static TEST_TEMPLATE3: &str = "tempX";
|
||||||
|
@ -501,6 +504,18 @@ fn test_respect_template_directory() {
|
||||||
assert!(at.file_exists(filename));
|
assert!(at.file_exists(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
#[test]
|
||||||
|
fn test_directory_permissions() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let result = ucmd.args(&["-d", "XXX"]).succeeds();
|
||||||
|
let dirname = result.no_stderr().stdout_str().trim_end();
|
||||||
|
assert_matches_template!("XXX", dirname);
|
||||||
|
let metadata = at.metadata(dirname);
|
||||||
|
assert!(metadata.is_dir());
|
||||||
|
assert_eq!(metadata.permissions().mode(), 0o40700);
|
||||||
|
}
|
||||||
|
|
||||||
/// Test that a template with a path separator is invalid.
|
/// Test that a template with a path separator is invalid.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_template_path_separator() {
|
fn test_template_path_separator() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue