Generated files are not recognized by libmagic

Reported by Gaël Utard on 2013-01-18
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Appy
Undecided
Unassigned

Bug Description

When using libmagic (eg. with the file shell command), files generated by appy.pod are detected as simple a Zip archive instead of an OpenDocument Text.

This blog post explain what should be done to fix the problem:
http://www.jejik.com/articles/2010/03/how_to_correctly_create_odf_documents_using_zip/

Hi Gaël,
Thanks for reporting this bug.
I have committed a fix:

=== modified file 'pod/renderer.py'
--- pod/renderer.py 2012-12-20 15:09:05 +0000
+++ pod/renderer.py 2013-01-22 15:28:41 +0000
@@ -499,14 +499,27 @@
             resultOdt = zipfile.ZipFile(resultOdtName,'w', zipfile.ZIP_DEFLATED)
         except RuntimeError:
             resultOdt = zipfile.ZipFile(resultOdtName,'w')
+ # Insert first the file "mimetype" (uncompressed), in order to be
+ # compliant with the OpenDocument Format specification, section 17.4,
+ # that has a restriction when it comes to zip containers: the file
+ # called "mimetype" must be at the beginning of the zip file, it must be
+ # uncompressed and it must be stored without any additional file
+ # attributes. Else, libraries like "magic", under Linux/Unix, are unable
+ # to detect the correct mimetype for POD results (it simply recognizes
+ # it as a "application/zip" and not a
+ # "application/vnd.oasis.opendocument.text)".
+ resultOdt.write(os.path.join(self.unzipFolder, 'mimetype'),
+ 'mimetype', zipfile.ZIP_STORED)
         for dir, dirnames, filenames in os.walk(self.unzipFolder):
             for f in filenames:
                 folderName = dir[len(self.unzipFolder)+1:]
+ # Ignore file "mimetype" that was already inserted.
+ if (folderName == '') and (f == 'mimetype'): continue
                 resultOdt.write(os.path.join(dir, f),
                                 os.path.join(folderName, f))
             if not dirnames and not filenames:

I have tested it by using, under Linux, the following command on a file re-zipped by pod and it seems to work:
file --mime onlyExpressions.odt
onlyExpressions.odt: application/vnd.oasis.opendocument.text

Could you please test it and see if you consider it to be OK?
If the solution is correct I will publish it in the upcoming Appy 0.8.3.
Cheers
Gaetan

Gaël Utard (gael-utard) wrote :

Hi Gaëtan,

Thanks a lot. I tested the fix. It works like a charm.

Gaël

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers