Commit graph

31 commits

Author SHA1 Message Date
Junji Wei
1ba0bfc67a mktemp: respect POSIXLY_CORRECT env var when parsing args
Signed-off-by: Junji Wei <harukawei99@gmail.com>
2022-06-09 20:51:51 +08:00
Jeffrey Finkelstein
6da070cdd3 mktemp: error on empty --suffix in some situations
Make `mktemp` exit with an error if the `--suffix` option is the empty
string and the template argument does not end in an "X". Previously,
the program succeeded.

Before this commit,

    $ mktemp --suffix= aXXXb
    apBEb

After this commit,

    $ mktemp --suffix= aXXXb
    mktemp: with --suffix, template 'aXXXb' must end in X
2022-06-06 21:24:59 -04:00
Sylvestre Ledru
3f203c7ab1
Merge pull request #3586 from jfinkels/mktemp-multiple-x-sequences
mktemp: only replace last contiguous block of Xs
2022-06-06 10:06:44 +02:00
Jeffrey Finkelstein
a9e008f230 mktemp: add test for combining --tmpdir, subdir
Add a unit test for combining the directory given in `--tmpdir` with
any subdirectory structure appearing in the prefix of the template
string. For example,

    $ mktemp --tmpdir=a b/cXXX
    a/b/cNqJ

This behavior is currently working, but a unit test was missing.
2022-06-01 18:22:17 -04:00
Jeffrey Finkelstein
cff7833bf6 mktemp: only replace last contiguous block of Xs
Fix a bug in which `mktemp` would replace everything in the template
argument from the first 'X' to the last 'X' with random bytes, instead
of just replacing the last contiguous block of 'X's.

Before this commit,

    $ mktemp XXX_XXX
    2meCpfM

After this commit,

    $ mktemp XXX_XXX
    XXX_Rp5

This fixes test cases `suffix2f` and `suffix2d` in
`tests/misc/mktemp.pl` in the GNU coreutils test suite.
2022-06-01 18:21:21 -04:00
Jeffrey Finkelstein
43e9fb73b1 mktemp: simplify file path parameter logic
Simplify the logic of computing the file path parameters (the
directory, prefix, suffix, and number of random characters) for the
temporary file created by `mktemp`. This commits adds an `Options`
struct as a layer of indirection between the application logic and
`clap`, and a `Params` struct whose associated function is responsible
for determining the file path parameters from the `Options`. This is
an improvement because the previous code had some logic for
determining file path parameters in one place and some in another
place.
2022-05-31 19:35:01 -04:00
Jeffrey Finkelstein
dfc1c8a2dd mktemp: exit with status 1 on usage errors 2022-05-30 09:30:47 -04:00
Sylvestre Ledru
fa577603c2
Merge pull request #3471 from 353fc443/mktemp-set-dir-mode
mktemp: change directory permission after creation
2022-05-25 14:56:45 +02:00
Jeffrey Finkelstein
35fb4e6ea1 mktemp: include suffix in error message
Include the suffix in the error message produced by `mktemp` when
there are too few Xs in the template. Before this commit,

    $ mktemp --suffix=X aXX
    mktemp: too few X's in template 'aXX'

After this commit,

    $ mktemp --suffix=X aXX
    mktemp: too few X's in template 'aXXX'

This matches the behavior of GNU `mktemp`.
2022-05-21 21:59:06 -04:00
Sylvestre Ledru
d92107362b
Merge pull request #3521 from jfinkels/mktemp-tmpdir-absolute-path
mktemp: correct error message on absolute path
2022-05-21 09:40:33 +02:00
Jeffrey Finkelstein
6260333415 mktemp: fix error msg when suffix has path sep.
Correct the error message when the template argument contains a path
separator in its suffix. Before this commit:

    $ mktemp aXXX/b
    mktemp: too few X's in template 'b'

After this commit:

    $ mktemp aXXX/b
    mktemp: invalid suffix '/b', contains directory separator

This error message is more appropriate and matches the behavior of GNU
mktemp.
2022-05-19 15:46:04 +02:00
Jeffrey Finkelstein
8a941db20a mktemp: correct error message on absolute path
Correct the error message produced by `mktemp` when `--tmpdir` is
given and the template is an absolute path:

    $ mktemp --tmpdir=a /XXX
    mktemp: invalid template, '/XXX'; with --tmpdir, it may not be absolute
2022-05-17 20:16:47 -04:00
353fc443 aka Seagull
2086d04996
Merge branch 'main' into mktemp-set-dir-mode 2022-05-17 04:58:03 +00:00
353fc443
2383950403
mktemp: Added tests for checking directory permissions 2022-05-16 18:05:59 +00:00
Jeffrey Finkelstein
2874f18950 mktemp: error on path separator in template prefix
Correct the error that arises from a path separator in the prefix
portion of a template argument provided to `mktemp`. Before this
commit, the error message was incorrect:

    $ mktemp -t a/bXXX
    mktemp: failed to create file via template 'a/bXXX': No such file or directory (os error 2) at path "/tmp/a/bege"

After this commit, the error message is correct:

    $ mktemp -t a/bXXX
    mktemp: invalid template, 'a/bXXX', contains directory separator

The code was failing to check for a path separator in the prefix
portion of the template.
2022-05-11 12:59:44 +02:00
Jeffrey Finkelstein
08816a4f05 fixup! mktemp: respect path given in template argument 2022-05-01 16:51:25 -04:00
Jeffrey Finkelstein
aa6aefbd64 mktemp: respect path given in template argument
Fix a bug in `mktemp` where it was not respecting the path given by
the positional argument. Previously, it would place the temporary file
whose name is induced by a given template in the `/tmp` directory,
like this:

    $ mktemp XXX
    /tmp/LJr

    $ mktemp d/XXX
    /tmp/d/IhS

After this commit, it respects the directory given in the template
argument:

    $ mktemp XXX
    LJr

    $ mktemp d/XXX
    d/IhS

Fixes #3440.
2022-05-01 13:03:18 -04:00
Terts Diepraam
73a7ead857 mktemp: adapt to standardized error handling 2021-06-28 13:55:55 +02:00
Michael Debertol
622504467f mktemp: note that windows uses a different env var for tmpdir
On windows `std::env::temp_dir` uses the `TMP` environment variable
instead of `TMPDIR`.
2021-06-22 17:44:45 +02:00
Michael Debertol
e5a7bcbb9d tests: keep env vars for the temporary directory
On some Windows machines this would otherwise cause `std::env::temp_dir`
to fall back to a path that is not writeable (C:\\Windows).
Since by default integration tests don't inherit env vars from the
parent, we have to override this in some cases.
2021-06-22 17:43:46 +02:00
Roy Ivy III
3f35e0a421 refactor ~ cargo make format 2021-05-31 08:23:58 -05:00
Roy Ivy III
4e20dedf58 tests ~ refactor/polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Jan Scheer
3aeccfd802 fix a lot of clippy warnings 2021-05-29 15:11:22 +02:00
Yağız can Değirmenci
071899d24d tests: delete 'error:' prefix from the tests 2021-05-26 02:45:53 +03:00
Gilad Naaman
93b03bf9a6 Ran cargo fmt 2021-04-18 02:33:52 +03:00
Gilad Naaman
7c7e64e79c pinky, mktemp: Remove direct usage of CmdResult fields in test 2021-04-17 15:14:49 +03:00
Sylvestre Ledru
b8987f3d5f
fix(mktemp) - Make mktemp --tempdir foo.XXXXXX works (#1716)
Used by apt-key
2021-02-11 00:03:23 +01:00
Sylvestre Ledru
e331186fee
unbreak build with rustc 1.32: force tempfile 3.1.0 (#1695) 2021-01-19 08:15:53 +01:00
Sylvestre Ledru
105e2cb26f 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
2021-01-02 13:07:27 +01:00
Sylvestre Ledru
ac34d136f2 refactor(global): Move from tempdir to tempfile:
* the crate has been deprecated
2020-06-09 11:30:19 +02:00
Roy Ivy III
de0375f909 tests ~ reorganize tests 2020-06-01 18:30:04 -05:00
Renamed from tests/test_mktemp.rs (Browse further)