From 33b78a595cf8009372fb6664727701d26fc8d09f Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 11 Nov 2003 22:37:25 +0000 Subject: [PATCH] recalculate SHA on template files when installed tracker used as template (sf bug 827510) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1978 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 2 ++ roundup/install_util.py | 41 +++++++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index e6ed2be..a8fbbef 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -27,6 +27,8 @@ Fixed: (bug #821364). - Centralised conversion of user-input data to hyperdb values (bug #802405, bug #817217, rfe #816994) +- recalculate SHA on template files when installed tracker used as + template (sf bug 827510) Cleanup: - Replace curuserid attribute on Database with the extended getuid() method. diff --git a/roundup/install_util.py b/roundup/install_util.py index e54dc93..4e07a5b 100644 --- a/roundup/install_util.py +++ b/roundup/install_util.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: install_util.py,v 1.8 2002-09-10 00:18:20 richard Exp $ +# $Id: install_util.py,v 1.9 2003-11-11 22:37:25 richard Exp $ __doc__ = """ Support module to generate and check fingerprints of installed files. @@ -30,29 +30,32 @@ slast_file_types = [".css"] digested_file_types = sgml_file_types + hash_file_types + slast_file_types - -def checkDigest(filename): - """Read file, check for valid fingerprint, return TRUE if ok""" - # open and read file - inp = open(filename, "r") - lines = inp.readlines() - inp.close() - +def extractFingerprint(lines): # get fingerprint from last line - if lines[-1][:6] == "#SHA: ": + if lines[-1].startswith("#SHA: "): # handle .py/.sh comment - fingerprint = lines[-1][6:].strip() - elif lines[-1][:10] == "', '') - fingerprint = fingerprint.strip() - elif lines[-1][:8] == "/* SHA: ": + return fingerprint.strip() + elif lines[-1].startswith("/* SHA: "): # handle css files fingerprint = lines[-1][8:] fingerprint = fingerprint.replace('*/', '') - fingerprint = fingerprint.strip() - else: + return fingerprint.strip() + return None + +def checkDigest(filename): + """Read file, check for valid fingerprint, return TRUE if ok""" + # open and read file + inp = open(filename, "r") + lines = inp.readlines() + inp.close() + + fingerprint = extractFingerprint(lines) + if fingerprint is None: return 0 del lines[-1] @@ -76,6 +79,12 @@ class DigestFile: self.file = open(self.filename, "w") def write(self, data): + lines = data.splitlines() + # if the file is coming from an installed tracker being used as a + # template, then we will want to re-calculate the SHA + fingerprint = extractFingerprint(lines) + if fingerprint is not None: + data = '\n'.join(lines[:-1]) + '\n' self.file.write(data) self.digest.update(data) -- 2.30.2