Modify

Opened 7 years ago

Last modified 5 years ago

#2150 new defect

On a Windows server, attached PNG and PDF files are corrupted

Reported by: goranw Owned by: chenca
Priority: normal Component: Trac2LatexPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.10

Description

NOTE: This issue has also been added as issue #1 on the Google Code site, and commented on the Introduction page...

I had the following issues when installing revision 70 on a Windows server:

What steps will reproduce the problem?

  1. 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
provided below...)

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"'

Attachments (0)

Change History (0)

Add Comment

Modify Ticket

Action
as new .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.