Opened 7 years ago

Closed 7 years ago

#4715 closed defect (fixed)

sugar-toolkit-gtk3: png file get wrong mime type

Reported by: godiard Owned by:
Priority: Unspecified by Maintainer Milestone: Unspecified
Component: Sugar Version: Unspecified
Severity: Unspecified Keywords:
Cc: Distribution/OS: Unspecified
Bug Status: Unconfirmed


Reported by AU:

"When try to download a image in Browse, the option 'Keep image' save something in the journal, but can't be opened"

In the xo or in sugar-build, if I do:

from sugar3 import mime


get 'application/octet-stream'.

Strangely in Fedora 18 (outside of sugar-build) I get 'image/png', then probably is a regression.

Gio.content_type_guess('/usr/share/icons/gnome/256x256/emotes/face-surprise.png', None)[0]

returns 'image/png' always.

We are using the two methods to identificate the mime type in sugar and in sugar toolkit:

[gonzalo@localhost sugar-toolkit-gtk3]$ grep -r content_type_guess * --include=*.py
src/sugar3/datastore/            'mime_type': Gio.content_type_guess(file_path, None)[0],
src/sugar3/activity/                       -1, Gio.content_type_guess(path, None)[0])
src/sugar3/activity/                       -1, Gio.content_type_guess(path, None)[0])
src/sugar3/bundle/        mime_type, certainty = Gio.content_type_guess(path, data=None)
[gonzalo@localhost sugar-toolkit-gtk3]$ cd ../sugar
[gonzalo@localhost sugar]$ grep -r content_type_guess * --include=*.py
src/jarabe/journal/                Gio.content_type_guess(filename=full_path, data=None)
src/jarabe/journal/    mime_type, uncertain_result_ = Gio.content_type_guess(filename=path,
[gonzalo@localhost sugar]$ grep -r mime.get_for_file * --include=*.py
src/jarabe/view/            mime_type = mime.get_for_file(self._document_path)
src/jarabe/view/        mime_type = mime.get_for_file(self._file_path)
src/jarabe/journal/            mime_type = mime.get_for_file(file_name)
src/jarabe/frame/                mime_type = mime.get_for_file(file_path)
src/jarabe/frame/                mime_type = mime.get_for_file(file_path)
src/jarabe/frame/                sniffed_mime_type = mime.get_for_file(file_path)
src/jarabe/frame/                    format_ = mime.get_for_file(path)
src/jarabe/frame/            mime_type = mime.get_for_file(path)
[gonzalo@localhost sugar]$ cd -
[gonzalo@localhost sugar-toolkit-gtk3]$ grep -r mime.get_for_file * --include=*.py
tests/        self.assertEqual(mime.get_for_file(os.path.join(data_dir, "mime.svg")),

mime.get_for_file use SugarExt.mime_get_mime_type_for_file() to recognize the files and add a little more logic to identify text files.

Attached is a simple patch to workaround this problem, but would be good know what is the source of the problem, and if possible unify the criteria in the code.

Attachments (1)

get_mime_from_gio_if_indeterminated.diff (550 bytes) - added by godiard 7 years ago.

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by godiard

comment:1 Changed 7 years ago by tch

At the specific method level, If both are idempotent, I don't see why we couldn't do it.

Still, the difference in the behavior depending on the environment is something we should trace.

comment:2 Changed 7 years ago by Gonzalo Odiard

  • Resolution set to fixed
  • Status changed from new to closed

Use Gio.content_type_guess to identify mime type - Fixes #4715

Replace the use of a custom implentation in SugarExt

Signed-off-by: Gonzalo Odiard <godiard@…>

Changeset: faa0d42084979400104032299936c84606afcd7b

Note: See TracTickets for help on using tickets.