Use mkdtempat instead of mkdtemp

This fixes an interaction of -C with incremental 'X'.
Problem reported by Pavel Cahyna.
* gnulib.modules: Remove mkdtemp.
Add tempname, since our mkdtempat uses it.
* lib/mkdtempat.c, lib/mkdtempat.h: New files.
* lib/Makefile.am (noinst_HEADERS): Add mkdtempat.h.
(libtar_a_SOURCES): Add mkdtempat.c.
* src/incremen.c: Include mkdtempat.h.
(purge_directory): Use mkdtempat, not mkdtemp.
This commit is contained in:
Paul Eggert
2026-04-12 23:58:22 -07:00
parent 0470c109c0
commit d479b2cc91
5 changed files with 53 additions and 2 deletions

View File

@@ -21,6 +21,7 @@
#include <c-ctype.h>
#include <flexmember.h>
#include <hash.h>
#include <mkdtempat.h>
#include <quotearg.h>
#include <same-inode.h>
#include "common.h"
@@ -1665,7 +1666,9 @@ purge_directory (char const *directory_name)
*copy_end = '/';
memcpy (copy_end + !ISSLASH (copy_end[-1]), TEMP_DIR_TEMPLATE,
sizeof TEMP_DIR_TEMPLATE);
if (!mkdtemp (temp_stub))
struct fdbase f = fdbase (temp_stub);
if (f.fd == BADFD
|| !mkdtempat (f.fd, temp_stub + (f.base - temp_stub)))
{
paxerror (errno, _("Cannot create temporary directory using template %s"),
quote (temp_stub));