mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-05 12:20:13 +02:00
Remove the cache expiration logic: it makes g_get_user_special_dir() not
2007-06-11 Emmanuele Bassi <ebassi@gnome.org> * glib/gutils.c (maybe_expire_user_special_dirs), (g_get_user_special_dir): Remove the cache expiration logic: it makes g_get_user_special_dir() not thread-safe. Document the fact that on some platform the value might be changed by the user and that GLib won't be able to reflect the change. svn path=/trunk/; revision=5550
This commit is contained in:
parent
c0890e2bc8
commit
72024709cc
@ -1,3 +1,11 @@
|
|||||||
|
2007-06-11 Emmanuele Bassi <ebassi@gnome.org>
|
||||||
|
|
||||||
|
* glib/gutils.c (maybe_expire_user_special_dirs),
|
||||||
|
(g_get_user_special_dir): Remove the cache expiration logic: it
|
||||||
|
makes g_get_user_special_dir() not thread-safe. Document the fact
|
||||||
|
that on some platform the value might be changed by the user and
|
||||||
|
that GLib won't be able to reflect the change.
|
||||||
|
|
||||||
2007-06-11 Tor Lillqvist <tml@novell.com>
|
2007-06-11 Tor Lillqvist <tml@novell.com>
|
||||||
|
|
||||||
* glib/gwin32.c (g_win32_get_package_installation_directory)
|
* glib/gwin32.c (g_win32_get_package_installation_directory)
|
||||||
|
@ -1400,8 +1400,6 @@ static gchar *g_user_config_dir = NULL;
|
|||||||
static gchar **g_system_config_dirs = NULL;
|
static gchar **g_system_config_dirs = NULL;
|
||||||
|
|
||||||
static gchar **g_user_special_dirs = NULL;
|
static gchar **g_user_special_dirs = NULL;
|
||||||
static time_t g_user_special_dirs_mtime = (time_t) -1;
|
|
||||||
static time_t g_user_special_dirs_stat_time = (time_t) -1;
|
|
||||||
|
|
||||||
/* fifteen minutes of fame for everybody */
|
/* fifteen minutes of fame for everybody */
|
||||||
#define G_USER_DIRS_EXPIRE 15 * 60
|
#define G_USER_DIRS_EXPIRE 15 * 60
|
||||||
@ -2188,78 +2186,10 @@ load_user_special_dirs (void)
|
|||||||
}
|
}
|
||||||
#endif /* G_OS_WIN32 */
|
#endif /* G_OS_WIN32 */
|
||||||
|
|
||||||
#if defined(G_OS_WIN32) || defined(HAVE_CARBON)
|
static void g_init_user_config_dir (void);
|
||||||
static void
|
|
||||||
maybe_expire_user_special_dirs (void)
|
|
||||||
{
|
|
||||||
/* expire the user dirs after G_USER_DIRS_EXPIRE seconds */
|
|
||||||
time_t now;
|
|
||||||
|
|
||||||
time (&now);
|
|
||||||
if (now > g_user_special_dirs_mtime + G_USER_DIRS_EXPIRE &&
|
|
||||||
g_user_special_dirs)
|
|
||||||
{
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
for (i = 0; i < G_USER_N_DIRECTORIES; i++)
|
|
||||||
g_free (g_user_special_dirs[i]);
|
|
||||||
|
|
||||||
g_free (g_user_special_dirs);
|
|
||||||
g_user_special_dirs = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_user_special_dirs == NULL)
|
|
||||||
g_user_special_dirs_mtime = now;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(G_OS_UNIX) && !defined(HAVE_CARBON)
|
#if defined(G_OS_UNIX) && !defined(HAVE_CARBON)
|
||||||
|
|
||||||
/* expire g_user_special_dirs if the config file
|
|
||||||
* was modified between different reads
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
maybe_expire_user_special_dirs (void)
|
|
||||||
{
|
|
||||||
gchar *config_file;
|
|
||||||
struct stat stat_buf;
|
|
||||||
time_t now;
|
|
||||||
|
|
||||||
/* don't stat() the file more often than necessary */
|
|
||||||
time (&now);
|
|
||||||
if (now < g_user_special_dirs_stat_time + 5)
|
|
||||||
return;
|
|
||||||
|
|
||||||
g_user_special_dirs_stat_time = now;
|
|
||||||
|
|
||||||
config_file = g_build_filename (g_user_config_dir,
|
|
||||||
"user-dirs.dirs",
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (stat (config_file, &stat_buf) < 0)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (stat_buf.st_mtime != g_user_special_dirs_mtime &&
|
|
||||||
g_user_special_dirs != NULL)
|
|
||||||
{
|
|
||||||
gint i;
|
|
||||||
|
|
||||||
for (i = 0; i < G_USER_N_DIRECTORIES; i++)
|
|
||||||
g_free (g_user_special_dirs[i]);
|
|
||||||
|
|
||||||
g_free (g_user_special_dirs);
|
|
||||||
g_user_special_dirs = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_user_special_dirs_mtime = stat_buf.st_mtime;
|
|
||||||
|
|
||||||
out:
|
|
||||||
g_free (config_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void g_init_user_config_dir (void);
|
|
||||||
|
|
||||||
/* adapted from xdg-user-dir-lookup.c
|
/* adapted from xdg-user-dir-lookup.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007 Red Hat Inc.
|
* Copyright (C) 2007 Red Hat Inc.
|
||||||
@ -2424,6 +2354,10 @@ load_user_special_dirs (void)
|
|||||||
*
|
*
|
||||||
* On Unix this is done using the XDG special user directories.
|
* On Unix this is done using the XDG special user directories.
|
||||||
*
|
*
|
||||||
|
* Depending on the platform, the user might be able to change the path
|
||||||
|
* of the special directory without requiring the session to restart; GLib
|
||||||
|
* will not reflect any change once the special directories are loaded.
|
||||||
|
*
|
||||||
* Return value: the path to the specified special directory, or %NULL
|
* Return value: the path to the specified special directory, or %NULL
|
||||||
* if the logical id was not found. The returned string is owned by
|
* if the logical id was not found. The returned string is owned by
|
||||||
* GLib and should not be modified or freed.
|
* GLib and should not be modified or freed.
|
||||||
@ -2438,8 +2372,7 @@ g_get_user_special_dir (GUserDirectory directory)
|
|||||||
|
|
||||||
G_LOCK (g_utils_global);
|
G_LOCK (g_utils_global);
|
||||||
|
|
||||||
maybe_expire_user_special_dirs ();
|
if (G_UNLIKELY (g_user_special_dirs == NULL))
|
||||||
if (g_user_special_dirs == NULL)
|
|
||||||
{
|
{
|
||||||
g_user_special_dirs = g_new0 (gchar *, G_USER_N_DIRECTORIES);
|
g_user_special_dirs = g_new0 (gchar *, G_USER_N_DIRECTORIES);
|
||||||
|
|
||||||
@ -2449,7 +2382,9 @@ g_get_user_special_dir (GUserDirectory directory)
|
|||||||
if (g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] == NULL)
|
if (g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] == NULL)
|
||||||
{
|
{
|
||||||
g_get_any_init ();
|
g_get_any_init ();
|
||||||
g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] = g_build_filename (g_home_dir, "Desktop", NULL);
|
|
||||||
|
g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] =
|
||||||
|
g_build_filename (g_home_dir, "Desktop", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user