mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-23 07:39:17 +02:00
Add g_reload_user_special_dirs_cache (#541276)
This is useful for nautilus that changes the xdg-user-dirs files.
This commit is contained in:
parent
740ae3aa29
commit
91bdccff75
@ -1562,6 +1562,7 @@ g_get_tmp_dir_utf8
|
|||||||
g_get_user_cache_dir
|
g_get_user_cache_dir
|
||||||
g_get_user_config_dir
|
g_get_user_config_dir
|
||||||
g_get_user_data_dir
|
g_get_user_data_dir
|
||||||
|
g_reload_user_special_dirs_cache
|
||||||
g_get_user_special_dir
|
g_get_user_special_dir
|
||||||
#ifndef _WIN64
|
#ifndef _WIN64
|
||||||
g_get_user_name PRIVATE
|
g_get_user_name PRIVATE
|
||||||
|
@ -2471,6 +2471,59 @@ load_user_special_dirs (void)
|
|||||||
|
|
||||||
#endif /* G_OS_UNIX && !HAVE_CARBON */
|
#endif /* G_OS_UNIX && !HAVE_CARBON */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_reload_user_special_dirs_cache:
|
||||||
|
*
|
||||||
|
* Resets the cache used for g_get_user_special_dir(), so
|
||||||
|
* that the latest on-disk version is used. Call this only
|
||||||
|
* if you just changed the data on disk yourself.
|
||||||
|
*
|
||||||
|
* Due to threadsafety issues this may cause leaking of strings
|
||||||
|
* that were previously returned from g_get_user_special_dir()
|
||||||
|
* that can't be freed. We ensure to only leak the data for
|
||||||
|
* the directories that actually changed value though.
|
||||||
|
*
|
||||||
|
* Since: 2.22
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
g_reload_user_special_dirs_cache (void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
G_LOCK (g_utils_global);
|
||||||
|
|
||||||
|
if (g_user_special_dirs != NULL)
|
||||||
|
{
|
||||||
|
/* save a copy of the pointer, to check if some memory can be preserved */
|
||||||
|
char **old_g_user_special_dirs = g_user_special_dirs;
|
||||||
|
char *old_val;
|
||||||
|
|
||||||
|
/* recreate and reload our cache */
|
||||||
|
g_user_special_dirs = g_new0 (gchar *, G_USER_N_DIRECTORIES);
|
||||||
|
load_user_special_dirs ();
|
||||||
|
|
||||||
|
/* only leak changed directories */
|
||||||
|
for (i = 0; i < G_USER_N_DIRECTORIES; i++)
|
||||||
|
{
|
||||||
|
old_val = old_g_user_special_dirs[i];
|
||||||
|
if (g_strcmp0 (old_val, g_user_special_dirs[i]) == 0)
|
||||||
|
{
|
||||||
|
/* don't leak */
|
||||||
|
g_free (g_user_special_dirs[i]);
|
||||||
|
g_user_special_dirs[i] = old_val;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g_free (old_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free the old array */
|
||||||
|
g_free (old_g_user_special_dirs);
|
||||||
|
}
|
||||||
|
|
||||||
|
G_UNLOCK (g_utils_global);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_get_user_special_dir:
|
* g_get_user_special_dir:
|
||||||
* @directory: the logical id of special directory
|
* @directory: the logical id of special directory
|
||||||
|
@ -127,6 +127,7 @@ void g_set_prgname (const gchar *prgname);
|
|||||||
G_CONST_RETURN gchar* g_get_application_name (void);
|
G_CONST_RETURN gchar* g_get_application_name (void);
|
||||||
void g_set_application_name (const gchar *application_name);
|
void g_set_application_name (const gchar *application_name);
|
||||||
|
|
||||||
|
void g_reload_user_special_dirs_cache (void);
|
||||||
G_CONST_RETURN gchar* g_get_user_data_dir (void);
|
G_CONST_RETURN gchar* g_get_user_data_dir (void);
|
||||||
G_CONST_RETURN gchar* g_get_user_config_dir (void);
|
G_CONST_RETURN gchar* g_get_user_config_dir (void);
|
||||||
G_CONST_RETURN gchar* g_get_user_cache_dir (void);
|
G_CONST_RETURN gchar* g_get_user_cache_dir (void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user