From c1b27e23baf0ca60d78c6aa325363dd541140ac8 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Wed, 05 Mar 2014 20:52:14 +0000 Subject: Save the mimetype in the metadata when download a shared file Some mime files, like epub, are not recognized if the extension is not set. We need use the suggested_name extension to save the file, and save the mimetype in the metadata. Signed-off-by: Gonzalo Odiard --- diff --git a/readactivity.py b/readactivity.py index 19ab4e1..ce39189 100644 --- a/readactivity.py +++ b/readactivity.py @@ -803,7 +803,16 @@ class ReadActivity(activity.Activity): del self.unused_download_tubes + # Use the suggested file, the mime is not recognized if the extension + # is wrong in some cases (epub) + temp_dir = os.path.dirname(tempfile) + new_name = os.path.join(temp_dir, suggested_name) + os.rename(tempfile, new_name) + tempfile = new_name + _logger.debug("Saving file %s to datastore...", tempfile) + mimetype = Gio.content_type_guess(tempfile, None)[0] + self._jobject.metadata['mime_type'] = mimetype self._jobject.file_path = tempfile datastore.write(self._jobject) -- cgit v0.9.1