rpms/glib2/F-12 0001-xdgmime-sort-glob-hits-with-larger-weight-first.patch, NONE, 1.1 0007-Don-t-give-up-too-early-when-collecting-mime-types.patch, NONE, 1.1 glib2.spec, 1.227, 1.228
Matthias Clasen
mclasen at fedoraproject.org
Sun Oct 25 07:02:13 UTC 2009
Author: mclasen
Update of /cvs/pkgs/rpms/glib2/F-12
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv7580
Modified Files:
glib2.spec
Added Files:
0001-xdgmime-sort-glob-hits-with-larger-weight-first.patch
0007-Don-t-give-up-too-early-when-collecting-mime-types.patch
Log Message:
Fix some problems with mime type detection in GIO
0001-xdgmime-sort-glob-hits-with-larger-weight-first.patch:
xdgmimecache.c | 2 +-
xdgmimeglob.c | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
--- NEW FILE 0001-xdgmime-sort-glob-hits-with-larger-weight-first.patch ---
>From 2a3710872f8bfc1c95dc8044c92c9ce020adad40 Mon Sep 17 00:00:00 2001
From: Alexander Larsson <alexl at redhat.com>
Date: Thu, 8 Oct 2009 11:59:23 +0200
Subject: [PATCH 1/8] xdgmime: sort glob hits with larger weight first
Higher weight is more important, so return these first meaning
they will be used as the default.
---
gio/xdgmime/xdgmimecache.c | 2 +-
gio/xdgmime/xdgmimeglob.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gio/xdgmime/xdgmimecache.c b/gio/xdgmime/xdgmimecache.c
index 6765787..97fe975 100644
--- a/gio/xdgmime/xdgmimecache.c
+++ b/gio/xdgmime/xdgmimecache.c
@@ -565,7 +565,7 @@ static int compare_mime_weight (const void *a, const void *b)
const MimeWeight *aa = (const MimeWeight *)a;
const MimeWeight *bb = (const MimeWeight *)b;
- return aa->weight - bb->weight;
+ return bb->weight - aa->weight;
}
#define ISUPPER(c) ((c) >= 'A' && (c) <= 'Z')
diff --git a/gio/xdgmime/xdgmimeglob.c b/gio/xdgmime/xdgmimeglob.c
index 2a0c777..c82bf22 100644
--- a/gio/xdgmime/xdgmimeglob.c
+++ b/gio/xdgmime/xdgmimeglob.c
@@ -381,7 +381,7 @@ static int compare_mime_weight (const void *a, const void *b)
const MimeWeight *aa = (const MimeWeight *)a;
const MimeWeight *bb = (const MimeWeight *)b;
- return aa->weight - bb->weight;
+ return bb->weight - aa->weight;
}
#define ISUPPER(c) ((c) >= 'A' && (c) <= 'Z')
--
1.6.5.1
0007-Don-t-give-up-too-early-when-collecting-mime-types.patch:
xdgmimecache.c | 67 +++++++++++++++++++++++++++++++++++++++++----------------
xdgmimeglob.c | 44 ++++++++++++++++++++++++++++++++-----
2 files changed, 87 insertions(+), 24 deletions(-)
--- NEW FILE 0007-Don-t-give-up-too-early-when-collecting-mime-types.patch ---
>From 58b65d312ba29cf4bec3ca46d86edfce5d8957b5 Mon Sep 17 00:00:00 2001
From: Matthias Clasen <mclasen at redhat.com>
Date: Sun, 25 Oct 2009 02:47:23 -0400
Subject: [PATCH 7/8] Don't give up too early when collecting mime types
Since returning exactly one match has special significance, don't
give up matching before we've found at least 2 types. Also, make
sure that we don't return the same mime type more than once.
Bug 541236.
---
gio/xdgmime/xdgmimecache.c | 67 ++++++++++++++++++++++++++++++++------------
gio/xdgmime/xdgmimeglob.c | 43 +++++++++++++++++++++++++---
2 files changed, 87 insertions(+), 23 deletions(-)
diff --git a/gio/xdgmime/xdgmimecache.c b/gio/xdgmime/xdgmimecache.c
index 97fe975..43cda89 100644
--- a/gio/xdgmime/xdgmimecache.c
+++ b/gio/xdgmime/xdgmimecache.c
@@ -444,11 +444,11 @@ cache_glob_lookup_fnmatch (const char *file_name,
}
}
- if (n > 0)
- return n;
+ if (n == n_mime_types)
+ break;
}
-
- return 0;
+
+ return n;
}
static int
@@ -539,6 +539,7 @@ cache_glob_lookup_suffix (const char *file_name,
{
int i, n;
+ n = 0;
for (i = 0; _caches[i]; i++)
{
XdgMimeCache *cache = _caches[i];
@@ -547,17 +548,17 @@ cache_glob_lookup_suffix (const char *file_name,
xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset);
xdg_uint32_t offset = GET_UINT32 (cache->buffer, list_offset + 4);
- n = cache_glob_node_lookup_suffix (cache,
- n_entries, offset,
- file_name, len,
- ignore_case,
- mime_types,
- n_mime_types);
- if (n > 0)
- return n;
+ n += cache_glob_node_lookup_suffix (cache,
+ n_entries, offset,
+ file_name, len,
+ ignore_case,
+ mime_types + n,
+ n_mime_types - n);
+ if (n == n_mime_types)
+ break;
}
- return 0;
+ return n;
}
static int compare_mime_weight (const void *a, const void *b)
@@ -585,7 +586,35 @@ ascii_tolower (const char *str)
}
static int
-cache_glob_lookup_file_name (const char *file_name,
+filter_out_dupes (MimeWeight mimes[], int n_mimes)
+{
+ int last;
+ int i, j;
+
+ last = n_mimes;
+
+ for (i = 0; i < last; i++)
+ {
+ j = i + 1;
+ while (j < last)
+ {
+ if (strcmp (mimes[i].mime, mimes[j].mime) == 0)
+ {
+ mimes[i].weight = MAX (mimes[i].weight, mimes[j].weight);
+ last--;
+ mimes[j].mime = mimes[last].mime;
+ mimes[j].weight = mimes[last].weight;
+ }
+ else
+ j++;
+ }
+ }
+
+ return last;
+}
+
+static int
+cache_glob_lookup_file_name (const char *file_name,
const char *mime_types[],
int n_mime_types)
{
@@ -619,14 +648,16 @@ cache_glob_lookup_file_name (const char *file_name,
len = strlen (file_name);
n = cache_glob_lookup_suffix (lower_case, len, FALSE, mimes, n_mimes);
- if (n == 0)
- n = cache_glob_lookup_suffix (file_name, len, TRUE, mimes, n_mimes);
+ if (n < 2)
+ n += cache_glob_lookup_suffix (file_name, len, TRUE, mimes + n, n_mimes - n);
free (lower_case);
/* Last, try fnmatch */
- if (n == 0)
- n = cache_glob_lookup_fnmatch (file_name, mimes, n_mimes);
+ if (n < 2)
+ n += cache_glob_lookup_fnmatch (file_name, mimes + n, n_mimes - n);
+
+ n = filter_out_dupes (mimes, n);
qsort (mimes, n, sizeof (MimeWeight), compare_mime_weight);
diff --git a/gio/xdgmime/xdgmimeglob.c b/gio/xdgmime/xdgmimeglob.c
index c82bf22..daea606 100644
--- a/gio/xdgmime/xdgmimeglob.c
+++ b/gio/xdgmime/xdgmimeglob.c
@@ -37,6 +37,10 @@
#include <string.h>
#include <fnmatch.h>
+#ifndef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
#ifndef FALSE
#define FALSE (0)
#endif
@@ -400,6 +404,34 @@ ascii_tolower (const char *str)
return lower;
}
+static int
+filter_out_dupes (MimeWeight mimes[], int n_mimes)
+{
+ int last;
+ int i, j;
+
+ last = n_mimes;
+
+ for (i = 0; i < last; i++)
+ {
+ j = i + 1;
+ while (j < last)
+ {
+ if (strcmp (mimes[i].mime, mimes[j].mime) == 0)
+ {
+ mimes[i].weight = MAX (mimes[i].weight, mimes[j].weight);
+ last--;
+ mimes[j].mime = mimes[last].mime;
+ mimes[j].weight = mimes[last].weight;
+ }
+ else
+ j++;
+ }
+ }
+
+ return last;
+}
+
int
_xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash,
const char *file_name,
@@ -412,7 +444,6 @@ _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash,
int n_mimes = 10;
int len;
char *lower_case;
- int try_lower_case;
/* First, check the literals */
@@ -447,11 +478,11 @@ _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash,
len = strlen (file_name);
n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, lower_case, len, FALSE,
mimes, n_mimes);
- if (n == 0)
- n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, file_name, len, TRUE,
- mimes, n_mimes);
+ if (n < 2)
+ n += _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, file_name, len, TRUE,
+ mimes + n, n_mimes - n);
- if (n == 0)
+ if (n < 2)
{
for (list = glob_hash->full_list; list && n < n_mime_types; list = list->next)
{
@@ -465,6 +496,8 @@ _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash,
}
free (lower_case);
+ n = filter_out_dupes (mimes, n);
+
qsort (mimes, n, sizeof (MimeWeight), compare_mime_weight);
if (n_mime_types < n)
--
1.6.5.1
Index: glib2.spec
===================================================================
RCS file: /cvs/pkgs/rpms/glib2/F-12/glib2.spec,v
retrieving revision 1.227
retrieving revision 1.228
diff -u -p -r1.227 -r1.228
--- glib2.spec 7 Oct 2009 14:58:59 -0000 1.227
+++ glib2.spec 25 Oct 2009 07:02:11 -0000 1.228
@@ -3,7 +3,7 @@
Summary: A library of handy utility functions
Name: glib2
Version: 2.22.2
-Release: 1%{?dist}
+Release: 2%{?dist}
License: LGPLv2+
Group: System Environment/Libraries
URL: http://www.gtk.org
@@ -21,6 +21,10 @@ BuildRequires: glibc-devel
BuildRequires: automake autoconf libtool
BuildRequires: gtk-doc
+# from upstream
+Patch0: 0001-xdgmime-sort-glob-hits-with-larger-weight-first.patch
+Patch1: 0007-Don-t-give-up-too-early-when-collecting-mime-types.patch
+
%description
GLib is the low-level core library that forms the basis
for projects such as GTK+ and GNOME. It provides data structure
@@ -52,6 +56,8 @@ of version 2 of the GLib library.
%prep
%setup -q -n glib-%{version}
+%patch0 -p1 -b .mime-weight
+%patch1 -p1 -b .mime-matches
%build
%configure --disable-gtk-doc --enable-static --with-runtime-libdir=../../%{_lib}
@@ -122,6 +128,9 @@ rm -rf $RPM_BUILD_ROOT
%{_libdir}/lib*.a
%changelog
+* Sun Oct 25 2009 Matthias Clasen <mclasen at redhat.com> - 2.22.2-2
+- Fix two problems with mime type detection in GIO
+
* Wed Oct 7 2009 Matthias Clasen <mclasen at redhat.com> - 2.22.2-1
- Update to 2.22.2
More information about the fedora-extras-commits
mailing list