From: Stephen Seo Date: Thu, 26 Dec 2024 01:50:52 +0000 (+0900) Subject: Fix temp_file setup for v0 file format X-Git-Tag: 1.10^2~5 X-Git-Url: https://git.seodisparate.com/stephenseo/client_config?a=commitdiff_plain;h=85fa618df9430ee124eb2298634a26c9aae2b98a;p=SimpleArchiver Fix temp_file setup for v0 file format --- diff --git a/src/archiver.c b/src/archiver.c index 3a8775a..f9ff1ec 100644 --- a/src/archiver.c +++ b/src/archiver.c @@ -187,28 +187,20 @@ int write_files_fn(void *data, void *ud) { } __attribute__((cleanup(simple_archiver_helper_cleanup_FILE))) FILE *tmp_fd = fopen(temp_filename, "wb"); + __attribute__((cleanup(cleanup_temp_filename_delete))) void **ptrs_array = + malloc(sizeof(void *) * 2); + ptrs_array[0] = NULL; + ptrs_array[1] = NULL; if (!tmp_fd) { - fprintf(stderr, "ERROR: Unable to create temp file for compressing!\n"); -#if SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_COSMOPOLITAN || \ - SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_MAC || \ - SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_LINUX - __attribute__(( - cleanup(simple_archiver_helper_cleanup_malloced))) void *real_cwd = - realpath(".", NULL); - if (real_cwd) { - fprintf(stderr, "Tried to create temp file(s) in \"%s\"!\n", - (char *)real_cwd); + tmp_fd = tmpfile(); + if (!tmp_fd) { + fprintf(stderr, "ERROR: Unable to create temp file for compressing!\n"); + return 1; } -#endif - fprintf(stderr, - "(Use \"--temp-files-dir \" to change where to write temp " - "files.)\n"); - return 1; + } else { + ptrs_array[0] = temp_filename; + ptrs_array[1] = &tmp_fd; } - __attribute__((cleanup(cleanup_temp_filename_delete))) void **ptrs_array = - malloc(sizeof(void *) * 2); - ptrs_array[0] = temp_filename; - ptrs_array[1] = &tmp_fd; // Handle SIGPIPE. signal(SIGPIPE, handle_sig_pipe);