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 | |
---|---|---|---|---|---|
Appy |
Fix Released
|
Undecided
|
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:
http://
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.
Hi Gaël,
Thanks for reporting this bug.
I have committed a fix:
=== modified file 'pod/renderer.py'
resultOdt = zipfile. ZipFile( resultOdtName, 'w', zipfile. ZIP_DEFLATED)
resultOdt = zipfile. ZipFile( resultOdtName, 'w') vnd.oasis. opendocument. text)". write(os. path.join( self.unzipFolde r, 'mimetype'), self.unzipFolde r):
folderName = dir[len( self.unzipFolde r)+1:]
resultOdt. write(os. path.join( dir, f),
os. path.join( folderName, f))
--- pod/renderer.py 2012-12-20 15:09:05 +0000
+++ pod/renderer.py 2013-01-22 15:28:41 +0000
@@ -499,14 +499,27 @@
except RuntimeError:
+ # 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/
+ resultOdt.
+ 'mimetype', zipfile.ZIP_STORED)
for dir, dirnames, filenames in os.walk(
for f in filenames:
+ # Ignore file "mimetype" that was already inserted.
+ if (folderName == '') and (f == 'mimetype'): continue
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: .odt: application/ vnd.oasis. opendocument. text
file --mime onlyExpressions.odt
onlyExpressions
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