From 2ed360005ad9265f45b32b1b19a202f747aed53c Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Thu, 13 Mar 2025 01:07:02 +0100 Subject: Rely on GSettings to setup temporary files. --- src/common/pathname.c | 23 ++++++++++++++++------- src/common/pathname.h | 2 -- src/schemas/re.chrysalide.framework.gschema.xml | 11 +++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/common/pathname.c b/src/common/pathname.c index dd3ec9e..81dc1e3 100644 --- a/src/common/pathname.c +++ b/src/common/pathname.c @@ -33,13 +33,13 @@ #include #include #include +#include #include #include "extstr.h" #include "io.h" #include "../core/logs.h" -//#include "../core/params.h" // TODO : config @@ -316,16 +316,19 @@ int ensure_path_exists(const char *path) * Remarques : - * * * ******************************************************************************/ -#if 0 // TODO + int make_tmp_file(const char *prefix, const char *suffix, char **filename) { int result; /* Flux ou code à retourner */ - const char *tmpdir; /* Répertoire d'accueil */ - bool status; /* Bilan d'un consultation */ + GSettings *settings; /* Configuration sollicitée */ + gchar *tmpdir; /* Répertoire d'accueil */ size_t slen; /* Taille du suffixe */ - status = g_generic_config_get_value(get_main_configuration(), MPK_TMPDIR, &tmpdir); - if (!status) return -1; + /* Récupération d'un répertoire de travail temporaire */ + + settings = g_settings_new("re.chrysalide.framework.paths"); + + tmpdir = g_settings_get_string(settings, "tmp-work-dir"); slen = strlen(suffix); @@ -334,6 +337,12 @@ int make_tmp_file(const char *prefix, const char *suffix, char **filename) else asprintf(filename, "%s" G_DIR_SEPARATOR_S "%s-%d.XXXXXX", tmpdir, prefix, getpid()); + g_free(tmpdir); + + g_clear_object(&settings); + + /* Mise en place d'un fichier temporaire */ + result = ensure_path_exists(*filename); if (result == 0) @@ -356,7 +365,7 @@ int make_tmp_file(const char *prefix, const char *suffix, char **filename) return result; } -#endif + /****************************************************************************** * * diff --git a/src/common/pathname.h b/src/common/pathname.h index 1b6624c..104833b 100644 --- a/src/common/pathname.h +++ b/src/common/pathname.h @@ -42,9 +42,7 @@ bool mkpath(const char *); int ensure_path_exists(const char *); /* Met en place un fichier temporaire. */ -#if 0 // TODO int make_tmp_file(const char *, const char *, char **); -#endif /* Copie un fichier. */ bool copy_file(const char *, const char *); diff --git a/src/schemas/re.chrysalide.framework.gschema.xml b/src/schemas/re.chrysalide.framework.gschema.xml index 87088f7..80a20db 100644 --- a/src/schemas/re.chrysalide.framework.gschema.xml +++ b/src/schemas/re.chrysalide.framework.gschema.xml @@ -1,10 +1,21 @@ + + + + "/tmp/chrysalide" + Directory for temporary contents + + Location of files created as cache and meant to get deleted when unused + + + + 600 -- cgit v0.11.2-87-g4458