On a Windows server, attached PNG and PDF files are corrupted
|Reported by:||goranw||Owned by:||chenca|
I had the following issues when installing revision 70 on a Windows server:
What steps will reproduce the problem?
- On the system described below, add some inlined Latex Processor code to a Trac wiki page (just like in the trac2latex example).
What is the expected output? What do you see instead?
The PNG and PDF files are attached as expected, but the inlined image is
not displayed. Also, when trying to view the attached files, they are
corrupted. The download as Latex-Pdf link does not work, either. (Solution
What version of the product are you using? On what operating system?
Revision 70 of Trac2LatexPlugin. Python 2.3.5 and Trac 0.10.4 on Windows
Server 2003 SP2.
Please provide any additional information below.
Causes for the above problems on Windows platforms are as follows:
- When extracting data from PNG and PDF files, they were opened for reading in text mode, not binary mode. This corrupts the extracted data.
- In convert_content(), when using mkstemp() to create a random file, the returned file descriptor was never closed. This lead to a locking problem when later doing clean_tmp_dir(). (NOTE: It is probably unnecessary to use a random file name here, since the temporary directory is created with mkdtemp() anyway...)
To solve the above problems I did the following changes:
- in LatexMacro.py - run_command(), I removed an extraneous "!" character in arguments of the first call to os.system("convert ...").
- in LatexMacro.py - add_attachment(), I changed the second arg to open(filename, "r") from "r" to "rb".
- in trac2latex.py - convert_content(), I changed the second arg to open(tmpfile + ".pdf", "r") from "r" to "rb".
- in trac2latex.py - convert_content(), I replaced the line 'fd, tmpfile = mkstemp(...)' with 'tmpfile = tempdir + "/trac2latex_output"'