summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6905eba)
The clean_temp module provided by gnulib doesn't cleanup on program
exit. We must do that ourselves. Secondly, the close_temp_file function
was supposed to remove the file, but didn't do that. Thirdly, files
were not being registered with the clean_temp module on creation.
This change fixes these problems.
{
ok = !ext_array_error (ea);
if (ea->file != NULL)
{
ok = !ext_array_error (ea);
if (ea->file != NULL)
+ close_temp_file (ea->file);
#include <config.h>
#include "libpspp/temp-file.h"
#include <config.h>
#include "libpspp/temp-file.h"
+#include "libpspp/hmapx.h"
+#include "libpspp/hash-functions.h"
- It honors the $TMPDIR environment variable.
- It honors the $TMPDIR environment variable.
- - The file will not be automatically deleted upon close. You have to call
- close_temp_file() if you want it to be deleted before the process exits.
+
+
+static struct temp_dir *temp_dir;
+struct hmapx map;
+
+static void
+setup (void)
+{
+ hmapx_init (&map);
+ temp_dir = create_temp_dir ("pspp", NULL, true);
+}
+
+static void
+cleanup (void)
+{
+ struct hmapx_node *node;
+ const char *fn;
+
+ cleanup_temp_dir (temp_dir);
+
+ HMAPX_FOR_EACH (fn, node, &map)
+ {
+ free (fn);
+ }
+
+ hmapx_destroy (&map);
+}
+
FILE *
create_temp_file (void)
{
static int idx = 0;
FILE *
create_temp_file (void)
{
static int idx = 0;
- static struct temp_dir *temp_dir;
char *file_name;
FILE *stream;
if (temp_dir == NULL)
{
char *file_name;
FILE *stream;
if (temp_dir == NULL)
{
- temp_dir = create_temp_dir ("pspp", NULL, true);
if (temp_dir == NULL)
return NULL;
if (temp_dir == NULL)
return NULL;
}
file_name = xasprintf ("%s/%d", temp_dir->dir_name, idx++);
}
file_name = xasprintf ("%s/%d", temp_dir->dir_name, idx++);
+ register_temp_file (temp_dir, file_name);
stream = fopen_temp (file_name, "wb+");
stream = fopen_temp (file_name, "wb+");
+ if (stream == NULL)
+ unregister_temp_file (temp_dir, file_name);
+ else
setvbuf (stream, NULL, _IOFBF, 65536);
setvbuf (stream, NULL, _IOFBF, 65536);
+
+ hmapx_insert (&map, file_name, hash_pointer (stream, 0));
close_temp_file (FILE *file)
{
if (file != NULL)
close_temp_file (FILE *file)
{
if (file != NULL)
+ {
+ struct hmapx_node *node = hmapx_first_with_hash (&map, hash_pointer (file, 0));
+ char *fn = node->data;
+ fclose_temp (file);
+ cleanup_temp_file (temp_dir, fn);
+ hmapx_delete (&map, node);
+ free (fn);
+ }
src/libpspp/temp-file.c \
tests/libpspp/heap-test.c
tests_libpspp_heap_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
src/libpspp/temp-file.c \
tests/libpspp/heap-test.c
tests_libpspp_heap_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
+tests_libpspp_heap_test_LDADD = src/libpspp/libpspp.la gl/libgl.la
tests_libpspp_hmap_test_SOURCES = \
src/libpspp/hmap.c \
tests_libpspp_hmap_test_SOURCES = \
src/libpspp/hmap.c \
src/libpspp/temp-file.c \
tests/libpspp/range-set-test.c
tests_libpspp_range_set_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
src/libpspp/temp-file.c \
tests/libpspp/range-set-test.c
tests_libpspp_range_set_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
+tests_libpspp_range_set_test_LDADD = src/libpspp/libpspp.la gl/libgl.la
tests_libpspp_str_test_SOURCES = \
tests/libpspp/str-test.c
tests_libpspp_str_test_SOURCES = \
tests/libpspp/str-test.c
src/libpspp/string-set.c \
tests/libpspp/string-map-test.c
tests_libpspp_string_map_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
src/libpspp/string-set.c \
tests/libpspp/string-map-test.c
tests_libpspp_string_map_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
+tests_libpspp_string_map_test_LDADD = src/libpspp/libpspp.la gl/libgl.la
tests_libpspp_stringi_map_test_SOURCES = \
src/libpspp/hash-functions.c \
tests_libpspp_stringi_map_test_SOURCES = \
src/libpspp/hash-functions.c \
src/libpspp/temp-file.c \
tests/libpspp/stringi-map-test.c
tests_libpspp_stringi_map_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
src/libpspp/temp-file.c \
tests/libpspp/stringi-map-test.c
tests_libpspp_stringi_map_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
+tests_libpspp_stringi_map_test_LDADD = src/libpspp/libpspp.la gl/libgl.la
tests_libpspp_string_set_test_SOURCES = \
src/libpspp/hash-functions.c \
tests_libpspp_string_set_test_SOURCES = \
src/libpspp/hash-functions.c \
src/libpspp/temp-file.c \
tests/libpspp/stringi-set-test.c
tests_libpspp_stringi_set_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
src/libpspp/temp-file.c \
tests/libpspp/stringi-set-test.c
tests_libpspp_stringi_set_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
+tests_libpspp_stringi_set_test_LDADD = src/libpspp/libpspp.la gl/libgl.la
tests_libpspp_tower_test_SOURCES = \
src/libpspp/abt.c \
tests_libpspp_tower_test_SOURCES = \
src/libpspp/abt.c \
src/libpspp/tower.c \
tests/libpspp/tower-test.c
tests_libpspp_tower_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
src/libpspp/tower.c \
tests/libpspp/tower-test.c
tests_libpspp_tower_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
+tests_libpspp_tower_test_LDADD = src/libpspp/libpspp.la gl/libgl.la
tests_libpspp_u8_istream_test_SOURCES = tests/libpspp/u8-istream-test.c
tests_libpspp_u8_istream_test_LDADD = src/libpspp/libpspp.la gl/libgl.la
tests_libpspp_u8_istream_test_SOURCES = tests/libpspp/u8-istream-test.c
tests_libpspp_u8_istream_test_LDADD = src/libpspp/libpspp.la gl/libgl.la
tests/libpspp/sparse-array-test.c \
src/libpspp/temp-file.c
tests_libpspp_sparse_array_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
tests/libpspp/sparse-array-test.c \
src/libpspp/temp-file.c
tests_libpspp_sparse_array_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
+tests_libpspp_sparse_array_test_LDADD = src/libpspp/libpspp.la gl/libgl.la
tests_libpspp_sparse_xarray_test_SOURCES = \
src/libpspp/argv-parser.c \
tests_libpspp_sparse_xarray_test_SOURCES = \
src/libpspp/argv-parser.c \
src/libpspp/temp-file.c \
tests/libpspp/sparse-xarray-test.c
tests_libpspp_sparse_xarray_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
src/libpspp/temp-file.c \
tests/libpspp/sparse-xarray-test.c
tests_libpspp_sparse_xarray_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
+tests_libpspp_sparse_xarray_test_LDADD = src/libpspp/libpspp.la gl/libgl.la
tests_data_inexactify_SOURCES = tests/data/inexactify.c
tests_data_inexactify_SOURCES = tests/data/inexactify.c
src/libpspp/temp-file.c \
tests/language/lexer/scan-test.c
tests_language_lexer_scan_test_CFLAGS = $(AM_CFLAGS)
src/libpspp/temp-file.c \
tests/language/lexer/scan-test.c
tests_language_lexer_scan_test_CFLAGS = $(AM_CFLAGS)
+tests_language_lexer_scan_test_LDADD = \
+ src/libpspp/libpspp.la \
+ gl/libgl.la
check_PROGRAMS += tests/language/lexer/segment-test
tests_language_lexer_segment_test_SOURCES = \
check_PROGRAMS += tests/language/lexer/segment-test
tests_language_lexer_segment_test_SOURCES = \
src/libpspp/temp-file.c \
tests/language/lexer/segment-test.c
tests_language_lexer_segment_test_CFLAGS = $(AM_CFLAGS)
src/libpspp/temp-file.c \
tests/language/lexer/segment-test.c
tests_language_lexer_segment_test_CFLAGS = $(AM_CFLAGS)
+tests_language_lexer_segment_test_LDADD = \
+ src/libpspp/libpspp.la \
+ gl/libgl.la
check_PROGRAMS += tests/libpspp/zip-test
tests_libpspp_zip_test_SOURCES = \
check_PROGRAMS += tests/libpspp/zip-test
tests_libpspp_zip_test_SOURCES = \
src/libpspp/zip-writer.c \
tests/libpspp/zip-test.c
tests_libpspp_zip_test_CFLAGS = $(AM_CFLAGS)
src/libpspp/zip-writer.c \
tests/libpspp/zip-test.c
tests_libpspp_zip_test_CFLAGS = $(AM_CFLAGS)
+tests_libpspp_zip_test_LDADD = \
+ src/libpspp/libpspp.la \
+ gl/libgl.la
check_PROGRAMS += tests/output/render-test
check_PROGRAMS += tests/output/render-test