summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2025-03-13 00:07:02 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2025-03-13 00:07:02 (GMT)
commit2ed360005ad9265f45b32b1b19a202f747aed53c (patch)
tree931649ea1253cd5f3eae753d7cd4e949bbfe53fe
parentccb49530f930701b1ca57e560564ae098dcef3c9 (diff)
Rely on GSettings to setup temporary files.
-rw-r--r--src/common/pathname.c23
-rw-r--r--src/common/pathname.h2
-rw-r--r--src/schemas/re.chrysalide.framework.gschema.xml11
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 <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <gio/gio.h>
#include <sys/stat.h>
#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 @@
<schemalist gettext-domain="chrysalide">
<schema id="re.chrysalide.framework" path="/re/chrysalide/framework/">
+ <child schema="re.chrysalide.framework.paths" name="paths"/>
<child schema="re.chrysalide.framework.gui" name="gui"/>
<child schema="re.chrysalide.framework.secstorage" name="secstorage"/>
</schema>
+ <schema id="re.chrysalide.framework.paths" path="/re/chrysalide/framework/paths/">
+ <key name="tmp-work-dir" type="s">
+ <default>"/tmp/chrysalide"</default>
+ <summary>Directory for temporary contents</summary>
+ <description>
+ Location of files created as cache and meant to get deleted when unused
+ </description>
+ </key>
+ </schema>
+
<schema id="re.chrysalide.framework.gui" path="/re/chrysalide/framework/gui/">
<key name="window-width" type="i">
<default>600</default>