mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
feature(mktemp): implement -t
Deprecated but used in various places: https://sources.debian.org/src/libreoffice/1:7.0.4-1/solenv/gbuild/platform/solaris.mk/?hl=22#L22 https://sources.debian.org/src/glibc/2.31-6/malloc/memusage.sh/?hl=225#L225 https://sources.debian.org/src/sbox-dtc/1.11.7-1/debian/postinst/?hl=20#L20
This commit is contained in:
parent
66b503a77e
commit
105e2cb26f
2 changed files with 73 additions and 7 deletions
|
@ -32,6 +32,7 @@ static OPT_DRY_RUN: &str = "dry-run";
|
|||
static OPT_QUIET: &str = "quiet";
|
||||
static OPT_SUFFIX: &str = "suffix";
|
||||
static OPT_TMPDIR: &str = "tmpdir";
|
||||
static OPT_T: &str = "t";
|
||||
|
||||
static ARG_TEMPLATE: &str = "template";
|
||||
|
||||
|
@ -79,12 +80,16 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.long(OPT_TMPDIR)
|
||||
.help(
|
||||
"interpret TEMPLATE relative to DIR; if DIR is not specified, use \
|
||||
$TMPDIR if set, else /tmp. With this option, TEMPLATE must not \
|
||||
be an absolute name; unlike with -t, TEMPLATE may contain \
|
||||
$TMPDIR if set, else /tmp. With this option, TEMPLATE must not \
|
||||
be an absolute name; unlike with -t, TEMPLATE may contain \
|
||||
slashes, but mktemp creates only the final component",
|
||||
)
|
||||
.value_name("DIR"),
|
||||
)
|
||||
.arg(Arg::with_name(OPT_T).short(OPT_T).help(
|
||||
"Generate a template (using the supplied prefix and TMPDIR if set) \
|
||||
to create a filename template [deprecated]",
|
||||
))
|
||||
.arg(
|
||||
Arg::with_name(ARG_TEMPLATE)
|
||||
.multiple(false)
|
||||
|
@ -93,10 +98,6 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
.default_value(DEFAULT_TEMPLATE),
|
||||
)
|
||||
.get_matches_from(args);
|
||||
// deprecated option of GNU coreutils
|
||||
// .arg(
|
||||
// Arg::with_name(("t", "", "Generate a template (using the supplied prefix and TMPDIR if set) \
|
||||
// to create a filename template");
|
||||
|
||||
let template = matches.value_of(ARG_TEMPLATE).unwrap();
|
||||
|
||||
|
@ -129,7 +130,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
crash!(1, "suffix cannot contain any path separators");
|
||||
}
|
||||
|
||||
let tmpdir = match matches.value_of(OPT_TMPDIR) {
|
||||
let mut tmpdir = match matches.value_of(OPT_TMPDIR) {
|
||||
Some(s) => {
|
||||
if PathBuf::from(prefix).is_absolute() {
|
||||
show_info!(
|
||||
|
@ -143,6 +144,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
None => env::temp_dir(),
|
||||
};
|
||||
|
||||
if matches.is_present(OPT_T) {
|
||||
tmpdir = env::temp_dir()
|
||||
};
|
||||
|
||||
if dry_run {
|
||||
dry_exec(tmpdir, prefix, rand, &suffix)
|
||||
} else {
|
||||
|
|
|
@ -65,6 +65,67 @@ fn test_mktemp_mktemp() {
|
|||
.fails();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mktemp_mktemp_t() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
||||
let pathname = scene.fixtures.as_string();
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.env(TMPDIR, &pathname)
|
||||
.arg("-t")
|
||||
.arg(TEST_TEMPLATE1)
|
||||
.succeeds();
|
||||
scene
|
||||
.ucmd()
|
||||
.env(TMPDIR, &pathname)
|
||||
.arg("-t")
|
||||
.arg(TEST_TEMPLATE2)
|
||||
.fails();
|
||||
scene
|
||||
.ucmd()
|
||||
.env(TMPDIR, &pathname)
|
||||
.arg("-t")
|
||||
.arg(TEST_TEMPLATE3)
|
||||
.fails();
|
||||
scene
|
||||
.ucmd()
|
||||
.env(TMPDIR, &pathname)
|
||||
.arg("-t")
|
||||
.arg(TEST_TEMPLATE4)
|
||||
.fails();
|
||||
scene
|
||||
.ucmd()
|
||||
.env(TMPDIR, &pathname)
|
||||
.arg("-t")
|
||||
.arg(TEST_TEMPLATE5)
|
||||
.succeeds();
|
||||
scene
|
||||
.ucmd()
|
||||
.env(TMPDIR, &pathname)
|
||||
.arg("-t")
|
||||
.arg(TEST_TEMPLATE6)
|
||||
.succeeds();
|
||||
scene
|
||||
.ucmd()
|
||||
.env(TMPDIR, &pathname)
|
||||
.arg("-t")
|
||||
.arg(TEST_TEMPLATE7)
|
||||
.succeeds();
|
||||
let result = scene
|
||||
.ucmd()
|
||||
.env(TMPDIR, &pathname)
|
||||
.arg("-t")
|
||||
.arg(TEST_TEMPLATE8)
|
||||
.fails();
|
||||
println!("stdout {}", result.stdout);
|
||||
println!("stderr {}", result.stderr);
|
||||
assert!(result
|
||||
.stderr
|
||||
.contains("error: suffix cannot contain any path separators"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mktemp_make_temp_dir() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue