mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-12-12 11:33:02 +01:00
Rework the timestamp checking code to protect against duplicate
2008-04-16 Matthias Clasen <mclasen@redhat.com> * xdgmime/xdgmime.c: Rework the timestamp checking code to protect against duplicate directories in XDG_DATA_DIRS. Fixes fd.o bug 12513, reported by Joe Shaw. svn path=/trunk/; revision=6859
This commit is contained in:
committed by
Matthias Clasen
parent
07ad3555ed
commit
9fd295d285
@@ -1,3 +1,9 @@
|
|||||||
|
2008-04-16 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* xdgmime/xdgmime.c: Rework the timestamp checking code
|
||||||
|
to protect against duplicate directories in XDG_DATA_DIRS.
|
||||||
|
Fixes fd.o bug 12513, reported by Joe Shaw.
|
||||||
|
|
||||||
2008-04-16 Matthias Clasen <mclasen@redhat.com>
|
2008-04-16 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
Partically revert the last commit after realizing that
|
Partically revert the last commit after realizing that
|
||||||
|
|||||||
@@ -93,17 +93,26 @@ struct XdgCallbackList
|
|||||||
typedef int (*XdgDirectoryFunc) (const char *directory,
|
typedef int (*XdgDirectoryFunc) (const char *directory,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
static XdgDirTimeList *
|
static void
|
||||||
xdg_dir_time_list_new (void)
|
xdg_dir_time_list_add (char *file_name,
|
||||||
|
time_t mtime)
|
||||||
{
|
{
|
||||||
XdgDirTimeList *retval;
|
XdgDirTimeList *list;
|
||||||
|
|
||||||
retval = calloc (1, sizeof (XdgDirTimeList));
|
for (list = dir_time_list; list; list = list->next)
|
||||||
retval->checked = XDG_CHECKED_UNCHECKED;
|
{
|
||||||
|
if (strcmp (list->directory_name, file_name) == 0)
|
||||||
return retval;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
list = calloc (1, sizeof (XdgDirTimeList));
|
||||||
|
list->checked = XDG_CHECKED_UNCHECKED;
|
||||||
|
list->directory_name = file_name;
|
||||||
|
list->mtime = mtime;
|
||||||
|
list->next = dir_time_list;
|
||||||
|
dir_time_list = list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xdg_dir_time_list_free (XdgDirTimeList *list)
|
xdg_dir_time_list_free (XdgDirTimeList *list)
|
||||||
{
|
{
|
||||||
@@ -123,7 +132,6 @@ xdg_mime_init_from_directory (const char *directory)
|
|||||||
{
|
{
|
||||||
char *file_name;
|
char *file_name;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
XdgDirTimeList *list;
|
|
||||||
|
|
||||||
assert (directory != NULL);
|
assert (directory != NULL);
|
||||||
|
|
||||||
@@ -135,11 +143,7 @@ xdg_mime_init_from_directory (const char *directory)
|
|||||||
|
|
||||||
if (cache != NULL)
|
if (cache != NULL)
|
||||||
{
|
{
|
||||||
list = xdg_dir_time_list_new ();
|
xdg_dir_time_list_add (file_name, st.st_mtime);
|
||||||
list->directory_name = file_name;
|
|
||||||
list->mtime = st.st_mtime;
|
|
||||||
list->next = dir_time_list;
|
|
||||||
dir_time_list = list;
|
|
||||||
|
|
||||||
_caches = realloc (_caches, sizeof (XdgMimeCache *) * (n_caches + 2));
|
_caches = realloc (_caches, sizeof (XdgMimeCache *) * (n_caches + 2));
|
||||||
_caches[n_caches] = cache;
|
_caches[n_caches] = cache;
|
||||||
@@ -156,12 +160,7 @@ xdg_mime_init_from_directory (const char *directory)
|
|||||||
if (stat (file_name, &st) == 0)
|
if (stat (file_name, &st) == 0)
|
||||||
{
|
{
|
||||||
_xdg_mime_glob_read_from_file (global_hash, file_name);
|
_xdg_mime_glob_read_from_file (global_hash, file_name);
|
||||||
|
xdg_dir_time_list_add (file_name, st.st_mtime);
|
||||||
list = xdg_dir_time_list_new ();
|
|
||||||
list->directory_name = file_name;
|
|
||||||
list->mtime = st.st_mtime;
|
|
||||||
list->next = dir_time_list;
|
|
||||||
dir_time_list = list;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -173,12 +172,7 @@ xdg_mime_init_from_directory (const char *directory)
|
|||||||
if (stat (file_name, &st) == 0)
|
if (stat (file_name, &st) == 0)
|
||||||
{
|
{
|
||||||
_xdg_mime_magic_read_from_file (global_magic, file_name);
|
_xdg_mime_magic_read_from_file (global_magic, file_name);
|
||||||
|
xdg_dir_time_list_add (file_name, st.st_mtime);
|
||||||
list = xdg_dir_time_list_new ();
|
|
||||||
list->directory_name = file_name;
|
|
||||||
list->mtime = st.st_mtime;
|
|
||||||
list->next = dir_time_list;
|
|
||||||
dir_time_list = list;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -296,12 +290,11 @@ xdg_check_file (const char *file_path,
|
|||||||
|
|
||||||
for (list = dir_time_list; list; list = list->next)
|
for (list = dir_time_list; list; list = list->next)
|
||||||
{
|
{
|
||||||
if (! strcmp (list->directory_name, file_path) &&
|
if (! strcmp (list->directory_name, file_path))
|
||||||
st.st_mtime == list->mtime)
|
|
||||||
{
|
{
|
||||||
if (list->checked == XDG_CHECKED_UNCHECKED)
|
if (st.st_mtime == list->mtime)
|
||||||
list->checked = XDG_CHECKED_VALID;
|
list->checked = XDG_CHECKED_VALID;
|
||||||
else if (list->checked == XDG_CHECKED_VALID)
|
else
|
||||||
list->checked = XDG_CHECKED_INVALID;
|
list->checked = XDG_CHECKED_INVALID;
|
||||||
|
|
||||||
return (list->checked != XDG_CHECKED_VALID);
|
return (list->checked != XDG_CHECKED_VALID);
|
||||||
|
|||||||
Reference in New Issue
Block a user