Opened 9 years ago
Closed 9 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 |
Description
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 mime.get_for_file('/usr/share/icons/gnome/256x256/emotes/face-surprise.png')
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/datastore.py: 'mime_type': Gio.content_type_guess(file_path, None)[0], src/sugar3/activity/webactivity.py: -1, Gio.content_type_guess(path, None)[0]) src/sugar3/activity/webkit1.py: -1, Gio.content_type_guess(path, None)[0]) src/sugar3/bundle/helpers.py: 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/model.py: Gio.content_type_guess(filename=full_path, data=None) src/jarabe/journal/model.py: mime_type, uncertain_result_ = Gio.content_type_guess(filename=path,
[gonzalo@localhost sugar]$ grep -r mime.get_for_file * --include=*.py src/jarabe/view/viewsource.py: mime_type = mime.get_for_file(self._document_path) src/jarabe/view/viewsource.py: mime_type = mime.get_for_file(self._file_path) src/jarabe/journal/palettes.py: mime_type = mime.get_for_file(file_name) src/jarabe/frame/clipboardmenu.py: mime_type = mime.get_for_file(file_path) src/jarabe/frame/clipboardmenu.py: mime_type = mime.get_for_file(file_path) src/jarabe/frame/clipboardmenu.py: sniffed_mime_type = mime.get_for_file(file_path) src/jarabe/frame/clipboardobject.py: format_ = mime.get_for_file(path) src/jarabe/frame/clipboard.py: mime_type = mime.get_for_file(path) [gonzalo@localhost sugar]$ cd - /home/gonzalo/sugar-build/sugar-toolkit-gtk3 [gonzalo@localhost sugar-toolkit-gtk3]$ grep -r mime.get_for_file * --include=*.py tests/test_mime.py: 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)
Change History (3)
Changed 9 years ago by godiard
comment:1 Changed 9 years ago by tch
comment:2 Changed 9 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
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.