Edgewall Software
Modify

Opened 18 years ago

Closed 18 years ago

Last modified 15 years ago

#3903 closed defect (fixed)

Binary files got currupted when viewing via TracMercurial plugin

Reported by: anonymous Owned by: Christian Boos
Priority: high Milestone: not applicable
Component: plugin/mercurial Version: 0.10
Severity: normal Keywords: mercurial
Cc: asl@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

I have Trac 0.10 installed among with TracMercurial plugin. Repository browsing works fine for text files, but doesn't for binary files. E.g. I have some images in the repository. Browser shows correct size for them, but downloaded file differs in size. Even more, only first 0x1000 bytes are valid. Others are just the first 0x1000 bytes iterating until the file ends.

Attachments (0)

Change History (6)

comment:1 by Christian Boos, 18 years ago

Keywords: mercurial added
Priority: normalhigh
Status: newassigned

Can you please try the following patch?

Index: backend.py
===================================================================
--- backend.py	(revision 3880)
+++ backend.py	(working copy)
@@ -323,6 +323,7 @@
         Node.__init__(self, path, rev, kind)
         self.created_path = path
         self.created_rev = rev
+        self.data = None
 
     def get_content(self):
         if self.isdir:
@@ -334,8 +335,14 @@
             return TracError("Can't read from directory %s" % self.path)
         file_n = self.manifest[self.path]
         file = self.repos.repo.file(self.path)
-        data = file.read(file_n)
-        return size and data[:size] or data
+        if self.data is None:
+            self.data = file.read(file_n)
+            self.pos = 0
+        if size:
+            prev_pos = self.pos
+            self.pos += size
+            return self.data[prev_pos:self.pos]
+        return data
 
     def get_entries(self):
         if self.isfile:

comment:2 by anonymous, 18 years ago

Thank you for fast respond! Everything works fine, but, please note, that "self.data" should be returned at line 345, not just "data".

comment:3 by anonymous, 18 years ago

Well, another check showed, that text files appeared as binary after the patch: it says something like "HTML preview not available".

Sometimes (in really random fashion) it displays html-formatted text, but only the last "chunk".

comment:4 by anonymous, 18 years ago

It seems, I've tracked down the problem.

  1. Everything works ok for "text" or "raw" format
  1. versioncontrol/web_ui/browser.py uses get_content() to pass file contents to renderer. get_content() call just returns the "self". But at the moment of get_content() call 1 chunk is already read (to detect mime type), thus self.pos is already set to CHUNK_SIZE. Surely, renderer gets just part of the file (or nothing at all). This patch works for me (I don't know, whether it's correct or not):
--- backend.py  2006-10-11 17:28:57.000000000 +0400
+++ backend.py  2006-10-11 17:30:56.540676287 +0400
@@ -328,8 +328,9 @@
     def get_content(self):
         if self.isdir:
             return None
-       self.pos = 0
-        return self # something that can be `read()` ...
+       obj = self
+       obj.pos = 0
+        return obj # something that can be `read()` ...

     def read(self, size=None):
         if self.isdir:

comment:5 by Christian Boos, 18 years ago

Resolution: fixed
Status: assignedclosed

Ha, at the same time I committed r3894, with a similar fix. Thanks for the feedback!

comment:6 by Christian Boos, 15 years ago

Component: version controlplugin/mercurial
Milestone: not applicable

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.