Generated files are not recognized by libmagic

Bug #1101237 reported by Gaël Utard
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Gaëtan Delannay

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:

Revision history for this message
Gaëtan Delannay (gaetan-delannay) wrote :

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

=== modified file 'pod/'
--- pod/ 2012-12-20 15:09:05 +0000
+++ pod/ 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.

Revision history for this message
Gaël Utard (gutard) wrote :

Hi Gaëtan,

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


Changed in appy:
status: New → Fix Released
milestone: none → 0.9.2
Changed in appy:
assignee: nobody → Gaëtan Delannay (gaetan-delannay)
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers