There are temporary files that need to be accessible by their name, after they have been completed. And there are temporary files that don't need that.
I don't remember why fatal-signal supports only the second category. Both need to be supported. 2020-06-27 Bruno Haible <br...@clisp.org> fatal-signal: 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/NEWS b/NEWS index 5684494..668f2d6 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 c57d658..b9badac 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 620bd08..5b66328 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 4717a5f..63efc2d 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);