From: Collin Funk Date: Sat, 11 Apr 2026 03:29:54 +0000 (-0700) Subject: mktemp: prefer rmdir and unlink to remove X-Git-Tag: v9.11~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79a6da3be7a815f252ba3195518c9f115cb5ffa3;p=thirdparty%2Fcoreutils.git mktemp: prefer rmdir and unlink to remove This avoids the following behavior: $ strace -e silence=exit -e trace=unlink,rmdir \ mktemp -d > /dev/full unlink("/tmp/tmp.ZBuPmS9ZGD") = -1 EISDIR (Is a directory) rmdir("/tmp/tmp.ZBuPmS9ZGD") = 0 mktemp: write error: No space left on device In the above invocation we know that we created a directory, so we should not remove a regular file that must have been created by another process: $ strace -e silence=exit -e trace=unlink,rmdir \ ./src/mktemp -d > /dev/full rmdir("/tmp/tmp.hGbME1HmJr") = 0 mktemp: write error: No space left on device * src/mktemp.c (main): Prefer rmdir and unlink depending on whether we created a directory or regular file. * bootstrap.conf (gnulib_modules): Remove the remove module. --- diff --git a/bootstrap.conf b/bootstrap.conf index bc31a58623..aee0c4f337 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -248,7 +248,6 @@ gnulib_modules=" readtokens0 readutmp regex - remove renameat renameatu rmdir diff --git a/src/mktemp.c b/src/mktemp.c index 72523be642..1fa797266c 100644 --- a/src/mktemp.c +++ b/src/mktemp.c @@ -347,7 +347,7 @@ main (int argc, char **argv) if (!dry_run && ((stdout_closed = true), close_stream (stdout) != 0)) { int saved_errno = errno; - remove (dest_name); + (create_directory ? rmdir : unlink) (dest_name); if (!suppress_file_err) error (0, saved_errno, _("write error")); status = EXIT_FAILURE;