Bug 100733

Summary: Upstream many miscellaneous fixes from GLib and Chromium forks
Product: xdgmime Reporter: Michael Catanzaro <mcatanzaro>
Component: xdgmimeAssignee: Jonathan Blandford <jrb>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium CC: bugzilla, mcatanzaro, mclasen, rstrode
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Patch
Patch
Patch
Patch
Patch
Patch
Patches

Description Michael Catanzaro 2017-04-20 01:38:50 UTC
GLib contains a forked copy of xdgmime that contains many miscellaneous, clearly-correct fixes:

https://git.gnome.org/browse/glib/log/gio/xdgmime

These should be investigated and upstreamed as appropriate.
Comment 1 Bastien Nocera 2017-10-20 22:58:01 UTC
The person maintaining both is Matthias, and he said many years ago that he's not interested in bringing the forks closer together.
Comment 2 Michael Catanzaro 2017-10-21 00:16:32 UTC
(In reply to Bastien Nocera from comment #1)
> The person maintaining both is Matthias, and he said many years ago that
> he's not interested in bringing the forks closer together.

Why?

Right now we have three different repos to update (this one, glib, and WebKit) that are almost always out of sync, because contributors don't know about the other ones.

Is the upstream repo even used for anything? Why did you recently commit to it?
Comment 3 Bastien Nocera 2017-10-21 11:54:34 UTC
(In reply to Michael Catanzaro from comment #2)
> (In reply to Bastien Nocera from comment #1)
> > The person maintaining both is Matthias, and he said many years ago that
> > he's not interested in bringing the forks closer together.
> 
> Why?

Ask Matthias.

> Right now we have three different repos to update (this one, glib, and
> WebKit) that are almost always out of sync, because contributors don't know
> about the other ones.
> 
> Is the upstream repo even used for anything? Why did you recently commit to
> it?

I commit to it because it's necessary to keep the shared-mime-info test suite working.
Comment 4 Matthias Clasen 2017-10-26 15:15:57 UTC
I don't think the copy of xdgmime on fd.o is used by anybody, and I consider it unmaintained. If anybody wants to take it over, let me know. As for the copy in glib, I would appreciate if somebody wanted to fully integrate it in glib (ie give up the posix-only constraints that come from sharing this)
Comment 6 Michael Catanzaro 2018-06-30 22:48:43 UTC
Here's one from Chromium:


diff --git a/base/third_party/xdg_mime/xdgmime.c b/base/third_party/xdg_mime/xdgmime.c
index c7b16bb..6dc58c2 100644
--- a/base/third_party/xdg_mime/xdgmime.c
+++ b/base/third_party/xdg_mime/xdgmime.c
@@ -558,13 +558,13 @@ xdg_mime_get_mime_type_for_file (const char  *file_name,
   mime_type = _xdg_mime_magic_lookup_data (global_magic, data, bytes_read, NULL,
 					   mime_types, n);
 
-  free (data);
   fclose (file);
 
-  if (mime_type)
-    return mime_type;
+  if (!mime_type)
+    mime_type = _xdg_binary_or_text_fallback(data, bytes_read);
 
-  return _xdg_binary_or_text_fallback(data, bytes_read);
+  free (data);
+  return mime_type;
 }
 
 const char *


They have two more patches at https://chromium.googlesource.com/chromium/src/+log/master/base/third_party/xdg_mime.
Comment 7 Michael Catanzaro 2018-06-30 23:19:49 UTC
git-bz is broken for bugs.freedesktop.org (fails to steal session cookie) so I'll be doing this manually....
Comment 8 Michael Catanzaro 2018-06-30 23:20:05 UTC
Created attachment 140407 [details] [review]
Patch
Comment 9 Michael Catanzaro 2018-06-30 23:20:18 UTC
Created attachment 140408 [details] [review]
Patch
Comment 10 Michael Catanzaro 2018-06-30 23:20:39 UTC
Created attachment 140409 [details] [review]
Patch
Comment 11 Michael Catanzaro 2018-06-30 23:20:51 UTC
Created attachment 140410 [details] [review]
Patch
Comment 12 Michael Catanzaro 2018-06-30 23:21:06 UTC
Created attachment 140411 [details] [review]
Patch
Comment 13 Michael Catanzaro 2018-06-30 23:21:19 UTC
Created attachment 140412 [details] [review]
Patch
Comment 14 Bastien Nocera 2018-07-16 11:21:21 UTC
Comment on attachment 140412 [details] [review]
Patch

Review of attachment 140412 [details] [review]:
-----------------------------------------------------------------

::: src/xdgmimecache.c
@@ +122,5 @@
>  
>    /* Open the file and map it into memory */
> +  do
> +    fd = open (file_name, O_RDONLY|_O_BINARY, 0);
> +  while (fd == -1 && errno == EINTR);

This definitely needs braces. I'm also not a fan of do {} while loops but I guess this would do.
Comment 15 Bastien Nocera 2018-07-16 11:25:25 UTC
All the patches look alright, but the commit messages definitely need more information about the upstream fixes. Some explanation about the code that was changed would be useful, rather than having to either reference another bug tracker, or figure out what the problem was in the first place by reverse-engineering the fix.

Feel free to attach a single file for all the patches, or send them to me via email git-bz is still giving you grief.
Comment 16 Bastien Nocera 2018-07-16 14:02:29 UTC
Comment on attachment 140407 [details] [review]
Patch

Pushed the .gitignore patch (hopefully I'm making the right one obsolete).
Comment 17 Michael Catanzaro 2018-07-17 02:52:22 UTC
Created attachment 140657 [details] [review]
Patches

Here they are in one file, with improved commit messages, and braces around the do/while, and one more fix from WebKit that I had forgotten. However, git doesn't understand how to apply the patches when they're concatenated together in one file, so you'll probably have to manually separate them out again....
Comment 18 Bastien Nocera 2018-07-17 08:47:00 UTC
(In reply to Michael Catanzaro from comment #17)
> Created attachment 140657 [details] [review] [review]
> Patches
> 
> Here they are in one file, with improved commit messages, and braces around
> the do/while, and one more fix from WebKit that I had forgotten. However,
> git doesn't understand how to apply the patches when they're concatenated
> together in one file, so you'll probably have to manually separate them out
> again....

git am...
Comment 19 Bastien Nocera 2018-07-17 08:59:15 UTC
I've reworded the commit for the first patch slightly, removed periods at the end of URLs to make them clickable, changed the pointer arithmetic patch (it isn't illegal to do maths on void pointers, it's just that GCC defines this behaviour, other compilers will have undefined behaviour).

Thanks for the patches!
Comment 20 Michael Catanzaro 2018-07-17 15:58:49 UTC
Thanks for handling this, Bastien.

(In reply to Bastien Nocera from comment #19)
> (it isn't illegal to do maths on void pointers, it's just that GCC defines
> this behaviour, other compilers will have undefined behaviour).

Anyway, GCC started warning about it with the build flags we use for WebKit. :)

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.