Skip to content
Snippets Groups Projects
Commit 010b6f04 authored by Ludovico de Nittis's avatar Ludovico de Nittis :palm_tree:
Browse files

adverb: Remove unused locales temp dir


If we are not going to use the locales temp dir, we remove it
immediately. Otherwise it will be left in /tmp/ forever (usually until a
system reboot).

Fixes: #56

Signed-off-by: default avatarLudovico de Nittis <ludovico.denittis@collabora.com>
parent 9bf4b6d2
Branches
Tags
1 merge request!240adverb: Remove unused locales temp dir
Pipeline #8672 passed
...@@ -413,24 +413,17 @@ generate_locales (gchar **locpath_out, ...@@ -413,24 +413,17 @@ generate_locales (gchar **locpath_out,
g_autofree gchar *pvlg = NULL; g_autofree gchar *pvlg = NULL;
g_autofree gchar *this_path = NULL; g_autofree gchar *this_path = NULL;
g_autofree gchar *this_dir = NULL; g_autofree gchar *this_dir = NULL;
gboolean ret = FALSE;
g_return_val_if_fail (locpath_out == NULL || *locpath_out == NULL, FALSE); g_return_val_if_fail (locpath_out != NULL && *locpath_out == NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
temp_dir = g_dir_make_tmp ("pressure-vessel-locales-XXXXXX", error);
if (temp_dir == NULL)
{
if (error != NULL)
glnx_prefix_error (error,
"Cannot create temporary directory for locales");
return FALSE;
}
this_path = g_file_read_link ("/proc/self/exe", NULL); this_path = g_file_read_link ("/proc/self/exe", NULL);
this_dir = g_path_get_dirname (this_path); this_dir = g_path_get_dirname (this_path);
pvlg = g_build_filename (this_dir, "pressure-vessel-locale-gen", NULL); pvlg = g_build_filename (this_dir, "pressure-vessel-locale-gen", NULL);
temp_dir = g_dir_make_tmp ("pressure-vessel-locales-XXXXXX", error);
const char * const locale_gen_argv[] = const char * const locale_gen_argv[] =
{ {
pvlg, pvlg,
...@@ -439,6 +432,14 @@ generate_locales (gchar **locpath_out, ...@@ -439,6 +432,14 @@ generate_locales (gchar **locpath_out,
NULL NULL
}; };
if (temp_dir == NULL)
{
if (error != NULL)
glnx_prefix_error (error,
"Cannot create temporary directory for locales");
goto out;
}
if (!run_helper_sync (NULL, if (!run_helper_sync (NULL,
locale_gen_argv, locale_gen_argv,
NULL, NULL,
...@@ -449,7 +450,7 @@ generate_locales (gchar **locpath_out, ...@@ -449,7 +450,7 @@ generate_locales (gchar **locpath_out,
{ {
if (error != NULL) if (error != NULL)
glnx_prefix_error (error, "Cannot run pressure-vessel-locale-gen"); glnx_prefix_error (error, "Cannot run pressure-vessel-locale-gen");
return FALSE; goto out;
} }
if (child_stdout != NULL && child_stdout[0] != '\0') if (child_stdout != NULL && child_stdout[0] != '\0')
...@@ -468,22 +469,27 @@ generate_locales (gchar **locpath_out, ...@@ -468,22 +469,27 @@ generate_locales (gchar **locpath_out,
{ {
if (error != NULL) if (error != NULL)
glnx_prefix_error (error, "Unable to generate locales"); glnx_prefix_error (error, "Unable to generate locales");
return FALSE; goto out;
} }
/* else all locales were already present (exit status 0) */ /* else all locales were already present (exit status 0) */
dir = g_dir_open (temp_dir, 0, error); dir = g_dir_open (temp_dir, 0, error);
ret = TRUE;
if (dir == NULL || g_dir_read_name (dir) == NULL) if (dir == NULL || g_dir_read_name (dir) == NULL)
{ {
g_info ("No locales have been generated"); g_info ("No locales have been generated");
return TRUE; goto out;
} }
if (locpath_out != NULL) *locpath_out = g_steal_pointer (&temp_dir);
*locpath_out = g_steal_pointer (&temp_dir);
return TRUE; out:
if (*locpath_out == NULL && temp_dir != NULL)
_srt_rm_rf (temp_dir);
return ret;
} }
/* Only do async-signal-safe things here: see signal-safety(7) */ /* Only do async-signal-safe things here: see signal-safety(7) */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment