After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 788401 - PATCH: MacOS build cannot detect content type from content - xdgmime is not used
PATCH: MacOS build cannot detect content type from content - xdgmime is not used
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.54.x
Other Mac OS
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks: 788936 793137
 
 
Reported: 2017-10-01 16:05 UTC by Friedrich Beckmann
Modified: 2018-02-03 12:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Use of xdgmime in gosxcontenttype.c (1.58 KB, patch)
2017-10-02 01:48 UTC, Friedrich Beckmann
none Details | Review
Change of gio/Makefile.am (Comments regarding generated code are for macports) (1.34 KB, patch)
2017-10-02 01:49 UTC, Friedrich Beckmann
none Details | Review
Updated patch to use xdgmime system to guess content type from data (5.18 KB, patch)
2017-10-11 14:15 UTC, Friedrich Beckmann
none Details | Review
2nd update of patch to use xdgmime system to guess content type from data (5.15 KB, patch)
2017-10-14 04:11 UTC, Friedrich Beckmann
committed Details | Review

Description Friedrich Beckmann 2017-10-01 16:05:17 UTC
I noticed a problem with Macports quartz build for the adwaita-icon-theme which I tracked down to a problem of identifying the content type from pure data. This method is used in gtk-encode-symbolic-svg which is used in the install procedure for the adwaita icon theme on MacOS. However this problem will be there for all applications which want to identify content type by content. 

I have described the problem on Macports:

https://trac.macports.org/ticket/54962

The fundamental reason is that the MacOS build does not use the xdgmime system to identify the content type from content. This is different in the Unix/X11 build. I did some short research but I could not find a MacOS way to identify content type from content.

Should the xdgmime system not be included also in the MacOS version?
Comment 1 Friedrich Beckmann 2017-10-02 01:42:28 UTC
I fixed the problem by using the xdgmime system for content analysis to figure out the content type. I did a pull request in the macports project where the required patch can be found.

https://github.com/macports/macports-ports/pull/852

With this patch the adwait-icon-theme can be installed.
Comment 2 Friedrich Beckmann 2017-10-02 01:48:13 UTC
Created attachment 360737 [details] [review]
Use of xdgmime in gosxcontenttype.c

This is part 1 of the fix.
Comment 3 Friedrich Beckmann 2017-10-02 01:49:31 UTC
Created attachment 360738 [details] [review]
Change of gio/Makefile.am (Comments regarding generated code are for macports)

Part 2 of the patch
Comment 4 Friedrich Beckmann 2017-10-02 01:55:07 UTC
The Makefile.am changes are on top of some other patches from the macports project. However the idea is that xdgmime is also available in MacOS.
Comment 5 Philip Withnall 2017-10-02 12:50:07 UTC
Bug #784747 already covers some plans to add xdgmime support to MacOS. Does that fit in with what you were thinking?

Patrick, what do you think?
Comment 6 Friedrich Beckmann 2017-10-02 23:01:23 UTC
Hi Philip, thanks for your comment on my patch. I had a look at the patches
from Bug #784747. My understanding is that this is about changing the content type meaning from the Windows extensions like ".txt" to mime plus extensions where the format is to be defined.

My understanding of the current implementation is that content type depends on the system. As an example on Windows there is ".txt", on Unix "text/plain" and on MacOS "public.text".

My patch does not propose to change or modify the interface and meaning of content type as it is today. As already discussed in Bug #784747 this will impact the applications.

The implementation as it is today breaks the functionality of gtk-encode-symbolic-svg and probably all applications which rely on the detection of the content type from stream data on MacOS. Simply because this is not implemented in gosxcontenttype.c. 

Today gtk-encode-symbolic-svg is used to install adwaita-icon-theme on MacPorts and this is broken because this functionality is broken.

My patch simply uses xdgmime also on MacOS to detect mime-type from data. The mime-type is then converted to content type - so here to UTI on MacOS which is todays interface usage: UTI on MacOS.

As a side note the implementation gdk-pixbuf is inconsistent with the usage of mime-type and content type. Maybe this is symptomatic for other applications also but it is not the scope of my patch.

See: https://github.com/GNOME/gdk-pixbuf/blob/45997d6abebf589dd594c78dc6bf06f3a3d7430c/gdk-pixbuf/gdk-pixbuf-io.c#L879

The "mime-type" is retrieved in line 864 but this is in fact the content type. On MacOS this yields "public.text" because that is the only thing that the data analyzer in giolib can provide, although content is svg. The hard coded mime types like "text/plain" in line 865 are simply wrong and based on the assumption that "mime-type" would contain mime type.

Then in line 879 the mimes from the file module loaders are converted to content type which is correct. Then this is compared to the variable named mime_type which contains the content type. So apart from misleading naming this is correct. So my scope and purpose is

- No Change in interface meaning or API
- Fix the problem of missing content type analysis of stream data on MacOS by using existing xdgmime for this.
- Fix currently broken applications which break installation of packages on MacPorts.

So compared to the discussion in Bug #784747 I consider my patch a simple fix and no architectural interface change which impacts all applications.
Comment 7 Philip Withnall 2017-10-05 11:26:34 UTC
Since Patrick wrote the original OSX implementation of GContentType, I’ll let him answer about whether using xdgmime for content type detection on OSX fits in with his plans, or whether he had something else in mind.
Comment 8 Friedrich Beckmann 2017-10-05 13:48:07 UTC
Hi Philip, thanks for your comments.
Comment 9 Patrick Griffis (tingping) 2017-10-05 19:37:08 UTC
Known types on OSX are always going to be limited so falling back to xdgmime is a totally acceptable behavior IMO.
Comment 10 Philip Withnall 2017-10-10 11:07:27 UTC
Review of attachment 360738 [details] [review]:

::: gio/Makefile.am.orig
@@ -7,3 @@
-if APPINFO_IMPL_GENERIC
-SUBDIRS += xdgmime
-endif

This patch doesn’t apply cleanly to git master. Can you please update it and submit it as a git formatted patch? (`git format-patch`)
Comment 11 Philip Withnall 2017-10-10 11:10:36 UTC
Review of attachment 360737 [details] [review]:

Broadly looks OK to me, although I’ve spotted one problem.

Patrick, can you take a look too please, from the OS X point of view?

::: gio/gosxcontenttype.c.orig
@@ +436,3 @@
     {
+      const char *sniffed_mimetype;
+      int sniffed_prio;

sniffed_prio is never used. Either use it, or drop it and pass NULL to xdg_mime_get_mime_type_for_data() instead.
Comment 12 Friedrich Beckmann 2017-10-10 11:21:51 UTC
Hi Philip,

thanks for looking at the patch. I will send you an updated patch. These patches are based on the macports version where already some patches are applied. Therefore this is a patch on top of macports patch. You are right with sniffed_prio.

Friedrich
Comment 13 Patrick Griffis (tingping) 2017-10-10 23:06:49 UTC
(In reply to Philip Withnall from comment #11)
> Review of attachment 360737 [details] [review] [review]:
> 
> Broadly looks OK to me, although I’ve spotted one problem.
> 
> Patrick, can you take a look too please, from the OS X point of view?
> 

Other than what you mentioned it looks fine, I don't have an easy way to test it though.
Comment 14 Friedrich Beckmann 2017-10-11 14:15:15 UTC
Created attachment 361330 [details] [review]
Updated patch to use xdgmime system to guess content type from data

This is the same patch as the github pull request:
https://github.com/GNOME/glib/pull/20
Comment 15 Friedrich Beckmann 2017-10-11 14:17:34 UTC
For your convenience I created a github pull request
https://github.com/GNOME/glib/pull/20
which is identical to the patch attachment 361330 [details] [review].

I included the proposed change to remove the priority variable.
I also added a regression test for this.
Comment 16 Philip Withnall 2017-10-12 09:57:00 UTC
Review of attachment 361330 [details] [review]:

A few comments on the tests (thanks for adding that) and then it looks like it’s good to push.

::: gio/tests/contenttype.c
@@ +342,3 @@
+test_guess_svg_from_data (void)
+{
+  const guchar svgfilecontent[] = "<svg  xmlns=\"http://www.w3.org/2000/svg\"\

Make it `const gchar`, since it’s all ASCII.

@@ +349,3 @@
+
+  gboolean uncertain = TRUE;
+  gchar *res = g_content_type_guess(NULL, svgfilecontent, sizeof (svgfilecontent) - 1, &uncertain);

Nitpick: Our coding style requires a space before `(` in function calls.

@@ +353,3 @@
+  g_assert_cmpstr (res, ==, "public.svg-image");
+#elif defined(G_OS_WIN32)
+  /* g_assert_cmpstr (res, ==, ".svg"); */

Drop this instead of commenting it out.

@@ +354,3 @@
+#elif defined(G_OS_WIN32)
+  /* g_assert_cmpstr (res, ==, ".svg"); */
+  g_assert_cmpstr (res, ==, ".txt");

This seems unfortunately incorrect. Leave out the assertion (so we’re not encoding incorrect behaviour in the tests) and file a follow-up bug about it? Probably not worth fixing in this bug, since it’s scoped to OS X.

@@ +359,3 @@
+  g_assert_cmpstr (res, ==, "image/svg+xml");
+#endif
+  g_assert (!uncertain);

g_assert_false (uncertain);
Comment 17 Friedrich Beckmann 2017-10-14 04:11:30 UTC
Created attachment 361567 [details] [review]
2nd update of patch to use xdgmime system to guess content type from data

I included the proposed changes from Philip in the test section of the patch.
- Type guchar -> gchar
- Remove commented line and assertion
- false check
Comment 18 Philip Withnall 2017-10-14 07:53:34 UTC
Review of attachment 361567 [details] [review]:

Looks good, thanks.
Comment 19 Friedrich Beckmann 2017-10-14 07:56:34 UTC
Thanks for doing the review!
Comment 20 Friedrich Beckmann 2018-02-03 12:36:44 UTC
I openend Bug #793137 for the discussion about backporting the patches from here and from bug #788936 to 2.54