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 795544 - Add binary/textfile/zero size detection
Add binary/textfile/zero size detection
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.56.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2018-04-25 13:57 UTC by Bastien Nocera
Modified: 2018-05-10 11:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
xdgmime: Add better detection for text vs. binary and zero-sized files (5.66 KB, patch)
2018-05-02 14:00 UTC, Bastien Nocera
committed Details | Review

Description Bastien Nocera 2018-04-25 13:57:24 UTC
This would allow GIO to detect zero-sized files, and differentiate most binary and text files, and thus offer opening in a text editor for unknown text file types.

See those 2 commits for details:
https://cgit.freedesktop.org/xdg/xdgmime/commit/?id=5181175d5fdaa3832b0fd094cda0120b1fe92af6
https://cgit.freedesktop.org/xdg/xdgmime/commit/?id=9c5802b8da56187c5c6abaf70042d14b12d832a9

See also for possible caveat:
https://bugs.freedesktop.org/show_bug.cgi?id=97372
Comment 1 Philip Withnall 2018-04-26 09:25:04 UTC
What exactly are you proposing here?
Comment 2 Bastien Nocera 2018-04-26 09:31:03 UTC
Adding pretty much the same code as above to GLib's outdated copy so we can detect unknown mime-types a bit better.
Comment 3 Philip Withnall 2018-04-26 09:43:30 UTC
Oh, just updating gio/xdgmime from upstream? Sure. Patch welcome; I should be able to review it and get it in fairly fast.

Is it the kind of thing you’d want backporting to glib-2-56 too?
Comment 4 Bastien Nocera 2018-04-26 09:45:46 UTC
(In reply to Philip Withnall from comment #3)
> Oh, just updating gio/xdgmime from upstream? Sure. Patch welcome; I should
> be able to review it and get it in fairly fast.

Huh, no, Matthias wasn't interested in having the 2 copies of that code synchronised and they've diverged a lot since GIO appeared. So it would be applying that patch manually to our old and thoroughly modified copy.

> Is it the kind of thing you’d want backporting to glib-2-56 too?

It might be safe, we'll see when testing.
Comment 5 Bastien Nocera 2018-05-02 14:00:08 UTC
Created attachment 371617 [details] [review]
xdgmime: Add better detection for text vs. binary and zero-sized files

This detects zero-sized files to return the special-case
"application/x-zerosize" mime-type, as well as trying to differentiate
unknown file types based on their first 128 bytes of data, so that text
editors can automatically handle unknown text files.

Based on:
https://cgit.freedesktop.org/xdg/xdgmime/commit/?id=5181175d5fdaa3832b0fd094cda0120b1fe92af6
https://cgit.freedesktop.org/xdg/xdgmime/commit/?id=9c5802b8da56187c5c6abaf70042d14b12d832a9
Comment 6 Emmanuele Bassi (:ebassi) 2018-05-08 11:36:38 UTC
Review of attachment 371617 [details] [review]:

Looks good
Comment 7 Emmanuele Bassi (:ebassi) 2018-05-10 11:00:39 UTC
Attachment 371617 [details] pushed as 1c177ce - xdgmime: Add better detection for text vs. binary and zero-sized files