From: Bruno Haible Date: Sat, 27 Jun 2020 22:03:44 +0000 (+0200) Subject: clean-temp: Don't force deletion of temporary files on native Windows. X-Git-Tag: v1.0~3954 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=64a1a8244c07b83e5bf3eebfc6e358aa9d58c6a9;p=gnulib.git clean-temp: Don't force deletion of temporary files on native Windows. * lib/clean-temp.h (open_temp, fopen_temp): Add delete_on_close argument. * lib/clean-temp.c (open_temp, fopen_temp): Likewise. * NEWS: Mention the change. * lib/javacomp.c (write_temp_file): Update. --- diff --git a/ChangeLog b/ChangeLog index aefe56392d..7e046bc402 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2020-06-27 Bruno Haible + + clean-temp: Don't force deletion of temporary files on native Windows. + * lib/clean-temp.h (open_temp, fopen_temp): Add delete_on_close + argument. + * lib/clean-temp.c (open_temp, fopen_temp): Likewise. + * NEWS: Mention the change. + * lib/javacomp.c (write_temp_file): Update. + 2020-06-27 Bruno Haible fatal-signal: Make multithread-safe. diff --git a/NEWS b/NEWS index 5684494c8d..668f2d60c0 100644 --- a/NEWS +++ b/NEWS @@ -58,6 +58,10 @@ User visible incompatible changes Date Modules Changes +2020-06-27 clean-temp The functions open_temp, fopen_temp now take a + 'bool delete_on_close' argument. If in doubt, pass + false. + 2020-06-27 tempname The link requirements of these modules are changed mkdtemp from empty to $(LIB_GETRANDOM). mkstemp diff --git a/lib/clean-temp.c b/lib/clean-temp.c index c57d658171..b9badac748 100644 --- a/lib/clean-temp.c +++ b/lib/clean-temp.c @@ -630,7 +630,7 @@ unregister_fd (int fd) /* Open a temporary file in a temporary directory. Registers the resulting file descriptor to be closed. */ int -open_temp (const char *file_name, int flags, mode_t mode) +open_temp (const char *file_name, int flags, mode_t mode, bool delete_on_close) { int fd; int saved_errno; @@ -640,7 +640,7 @@ open_temp (const char *file_name, int flags, mode_t mode) #if defined _WIN32 && ! defined __CYGWIN__ /* Use _O_TEMPORARY when possible, to increase the chances that the temporary file is removed when the process crashes. */ - if (supports_delete_on_close ()) + if (delete_on_close && supports_delete_on_close ()) fd = open (file_name, flags | _O_TEMPORARY, mode); else #endif @@ -656,7 +656,7 @@ open_temp (const char *file_name, int flags, mode_t mode) /* Open a temporary file in a temporary directory. Registers the resulting file descriptor to be closed. */ FILE * -fopen_temp (const char *file_name, const char *mode) +fopen_temp (const char *file_name, const char *mode, bool delete_on_close) { FILE *fp; int saved_errno; @@ -666,7 +666,7 @@ fopen_temp (const char *file_name, const char *mode) #if defined _WIN32 && ! defined __CYGWIN__ /* Use _O_TEMPORARY when possible, to increase the chances that the temporary file is removed when the process crashes. */ - if (supports_delete_on_close ()) + if (delete_on_close && supports_delete_on_close ()) { size_t mode_len = strlen (mode); char *augmented_mode = (char *) xmalloca (mode_len + 2); diff --git a/lib/clean-temp.h b/lib/clean-temp.h index 620bd086c3..5b663286c8 100644 --- a/lib/clean-temp.h +++ b/lib/clean-temp.h @@ -117,9 +117,13 @@ extern int cleanup_temp_dir_contents (struct temp_dir *dir); extern int cleanup_temp_dir (struct temp_dir *dir); /* Open a temporary file in a temporary directory. - Registers the resulting file descriptor to be closed. */ -extern int open_temp (const char *file_name, int flags, mode_t mode); -extern FILE * fopen_temp (const char *file_name, const char *mode); + Registers the resulting file descriptor to be closed. + DELETE_ON_CLOSE indicates whether the file can be deleted when the resulting + file descriptor or stream is closed. */ +extern int open_temp (const char *file_name, int flags, mode_t mode, + bool delete_on_close); +extern FILE * fopen_temp (const char *file_name, const char *mode, + bool delete_on_close); /* Close a temporary file in a temporary directory. Unregisters the previously registered file descriptor. */ diff --git a/lib/javacomp.c b/lib/javacomp.c index 4717a5fd7d..63efc2d782 100644 --- a/lib/javacomp.c +++ b/lib/javacomp.c @@ -573,7 +573,7 @@ write_temp_file (struct temp_dir *tmpdir, const char *file_name, FILE *fp; register_temp_file (tmpdir, file_name); - fp = fopen_temp (file_name, "we"); + fp = fopen_temp (file_name, "we", false); if (fp == NULL) { error (0, errno, _("failed to create \"%s\""), file_name);