Bug 12513 - Including the same directory multiple times in XDG_DATA_DIRS causes cache to be excessively reloaded
Summary: Including the same directory multiple times in XDG_DATA_DIRS causes cache to ...
Status: RESOLVED MOVED
Alias: None
Product: xdgmime
Classification: Unclassified
Component: xdgmime (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Jonathan Blandford
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-21 12:29 UTC by Joe Shaw
Modified: 2018-10-13 10:34 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Joe Shaw 2007-09-21 12:29:14 UTC
xdg_check_time_and_dirs() will always return TRUE (assuming more than 5 seconds have passed), and xdg_mime_shutdown() will be called every time xdg_mime_init() is called.  This means the cache is constantly reloaded even if it hasn't changed.

This is because xdg_check_file() walks a linked list of directory names, and if the mtime is the same as it was previously, progressively changes the state from XDG_CHECKED_UNCHECKED to XDG_CHECKED_VALID to XDG_CHECKED_INVALID.

I don't understand why the progression from VALID to INVALID is present, it doesn't make sense to me.

The end result, though, is that if a directory is listed twice, the first instance in the linked list is hit twice.  Generally that means that the state is changed from UNCHECKED to VALID and then from VALID to INVALID (when it should hit the second instance of the directory and change its own UNCHECKED to VALID).

I think the right thing to do here is to remove the VALID -> INVALID progression entirely.
Comment 1 Matthias Clasen 2008-04-16 09:11:04 UTC
I agree that the valid -> invalid transition doesn't make much sense to me either, but the loop body in xdg_check_file confuses me anyway.

          if (! strcmp (list->directory_name, file_path) &&
              st.st_mtime == list->mtime)
            {
              if (list->checked == XDG_CHECKED_UNCHECKED)
                list->checked = XDG_CHECKED_VALID;
              else if (list->checked == XDG_CHECKED_VALID)
                list->checked = XDG_CHECKED_INVALID;

              return (list->checked != XDG_CHECKED_VALID);
            }

I would have expected that to be more like

if (! strcmp (list->directory_name, file_path))
  {
     if (list->checked == XDG_CHECKED_UNCHECKED) 
       {
         if (list->mtime == st.st_mtime)
           list->checked = XDG_CHECKED_VALID;
         else
           list->checked = XDG_CHECKED_INVALID;

         list->mtime = st.st_mtime; 
       }

     return list->checked == XDG_CHECKED_VALID;
  }

Also, I think we can just as well prevent xdg_mime_init_from_directory from ever adding duplicates to the list.
Comment 2 GitLab Migration User 2018-10-13 10:34:29 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/xdg/xdgmime/issues/22.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.