Checksum the project.py file to validate that the pickle we get from the project...
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 31 Oct 2017 15:48:43 +0000 (11:48 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 31 Oct 2017 15:48:43 +0000 (11:48 -0400)
This will rebuild all project if project.py changes. Not the best
solution but is good enough to prevent corruption.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
lttng_ivc/settings.py
lttng_ivc/utils/ProjectFactory.py
lttng_ivc/utils/project.py
lttng_ivc/utils/utils.py

index 7c9e3e43b1d9f81028733f53f77fa795bec46e58..bad61cffe453f88d6626b0ebd44fe298bba1cd13 100644 (file)
@@ -15,6 +15,9 @@ apps_folder = os.path.join(base_dir, "apps")
 apps_gen_events_folder = os.path.join(apps_folder, "gen_ust_events")
 apps_preload_provider_folder = os.path.join(apps_folder, "preload_provider")
 
+# Used for checksum validation
+project_py_file_location = os.path.join(base_dir, "utils/project.py")
+
 tmp_object_prefix = "lttng-ivc-"
 
 default_babeltrace = "babeltrace-1.5"
index 5daba558e17006ec24e512f6a600d6b3c667231b..f45b786c921dbd0be985d44e3618ee4157b7bc4b 100644 (file)
@@ -6,6 +6,7 @@ import pickle
 import lttng_ivc.utils.project as Project
 import lttng_ivc.settings as Settings
 
+from lttng_ivc.utils.utils import sha256_checksum
 
 _logger = logging.getLogger('project.factory')
 _project_constructor = {
@@ -17,6 +18,8 @@ _project_constructor = {
 
 __projects_cache = {}
 
+_project_py_checksum = sha256_checksum(Settings.project_py_file_location)
+
 _markers = None
 with open(Settings.run_configuration_file, 'r') as stream:
     # This is voluntary static across calls, no need to perform this
@@ -38,10 +41,15 @@ def get_fresh(label, tmpdir):
 
 def _validate_pickle(pickle, label):
     _logger.debug("Checking validate for {} {}".format(pickle,
-        label))
+                                                       label))
+    if pickle._py_file_checksum != _project_py_checksum:
+        _logger.warn("Project py file changed".format(pickle.label,
+                                                      label))
+        return False
+
     if pickle.label != label:
         _logger.warn("Label  {} and {} are not the same".format(pickle.label,
-            label))
+                                                                label))
         return False
     if pickle.sha1 != _markers[label]['sha1']:
         _logger.warn("Sha1  {} and {} are not the same".format(pickle.sha1,
index 7e9957113502fda537d2cc1115c979148e56188b..f508c31cd591b912ed2bbc60eeec9e3234466142 100644 (file)
@@ -3,6 +3,9 @@ import shutil
 import git
 import subprocess
 import logging
+import lttng_ivc.settings as Settings
+
+from lttng_ivc.utils.utils import sha256_checksum
 
 _logger = logging.getLogger('project')
 
@@ -23,7 +26,9 @@ class Project(object):
 
         """ A collection of Project dependencies """
         self.dependencies = {}
+        # used for project cache and pickle validation
         self._immutable = False
+        self._py_file_checksum = sha256_checksum(Settings.project_py_file_location)
 
         # State
         self.isBuilt = False
index aedb1fdb3c0ae62a0dd68ee531d608fbfaff3fa2..23ce4bce20ae3d2700d0bb57ace4d1cf5cbb7dcb 100644 (file)
@@ -1,4 +1,5 @@
 import signal
+import hashlib
 
 def line_count(file_path):
     line_count = 0
@@ -8,6 +9,14 @@ def line_count(file_path):
     return line_count
 
 
+def sha256_checksum(filename, block_size=65536):
+    sha256 = hashlib.sha256()
+    with open(filename, 'rb') as f:
+        for block in iter(lambda: f.read(block_size), b''):
+            sha256.update(block)
+    return sha256.hexdigest()
+
+
 def __dummy_sigusr1_handler():
     pass
 
This page took 0.02714 seconds and 5 git commands to generate.