Skip to content

Commit 90f2520

Browse files
author
Richard Jones
committed
recalculate SHA on template files when installed tracker used as template
[SF#827510]
1 parent 96d6e67 commit 90f2520

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Fixed:
2727
(bug #821364).
2828
- Centralised conversion of user-input data to hyperdb values (bug #802405,
2929
bug #817217, rfe #816994)
30+
- recalculate SHA on template files when installed tracker used as
31+
template (sf bug 827510)
3032

3133
Cleanup:
3234
- Replace curuserid attribute on Database with the extended getuid() method.

roundup/install_util.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: install_util.py,v 1.8 2002-09-10 00:18:20 richard Exp $
18+
# $Id: install_util.py,v 1.9 2003-11-11 22:37:25 richard Exp $
1919

2020
__doc__ = """
2121
Support module to generate and check fingerprints of installed files.
@@ -30,29 +30,32 @@
3030

3131
digested_file_types = sgml_file_types + hash_file_types + slast_file_types
3232

33-
34-
def checkDigest(filename):
35-
"""Read file, check for valid fingerprint, return TRUE if ok"""
36-
# open and read file
37-
inp = open(filename, "r")
38-
lines = inp.readlines()
39-
inp.close()
40-
33+
def extractFingerprint(lines):
4134
# get fingerprint from last line
42-
if lines[-1][:6] == "#SHA: ":
35+
if lines[-1].startswith("#SHA: "):
4336
# handle .py/.sh comment
44-
fingerprint = lines[-1][6:].strip()
45-
elif lines[-1][:10] == "<!-- SHA: ":
37+
return lines[-1][6:].strip()
38+
elif lines[-1].startswith("<!-- SHA: "):
4639
# handle xml/html files
4740
fingerprint = lines[-1][10:]
4841
fingerprint = fingerprint.replace('-->', '')
49-
fingerprint = fingerprint.strip()
50-
elif lines[-1][:8] == "/* SHA: ":
42+
return fingerprint.strip()
43+
elif lines[-1].startswith("/* SHA: "):
5144
# handle css files
5245
fingerprint = lines[-1][8:]
5346
fingerprint = fingerprint.replace('*/', '')
54-
fingerprint = fingerprint.strip()
55-
else:
47+
return fingerprint.strip()
48+
return None
49+
50+
def checkDigest(filename):
51+
"""Read file, check for valid fingerprint, return TRUE if ok"""
52+
# open and read file
53+
inp = open(filename, "r")
54+
lines = inp.readlines()
55+
inp.close()
56+
57+
fingerprint = extractFingerprint(lines)
58+
if fingerprint is None:
5659
return 0
5760
del lines[-1]
5861

@@ -76,6 +79,12 @@ def __init__(self, filename):
7679
self.file = open(self.filename, "w")
7780

7881
def write(self, data):
82+
lines = data.splitlines()
83+
# if the file is coming from an installed tracker being used as a
84+
# template, then we will want to re-calculate the SHA
85+
fingerprint = extractFingerprint(lines)
86+
if fingerprint is not None:
87+
data = '\n'.join(lines[:-1]) + '\n'
7988
self.file.write(data)
8089
self.digest.update(data)
8190

0 commit comments

Comments
 (0)