LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0010-Use-sorted-json-to-perform-hash-of-settings.patch of Package mycroft-core (Project home:alarrosa:packages)

From 1411ae8e3a3ed310062e96c5166f574265877181 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=85ke=20Forslund?= <ake.forslund@gmail.com>
Date: Fri, 9 Feb 2018 09:32:43 +0100
Subject: [PATCH 10/13] Use sorted json to perform hash of settings

---
 mycroft/skills/settings.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mycroft/skills/settings.py b/mycroft/skills/settings.py
index 12bdce4..90a72a3 100644
--- a/mycroft/skills/settings.py
+++ b/mycroft/skills/settings.py
@@ -94,7 +94,7 @@ class SkillSettings(dict):
         self._settings_path = join(directory, 'settings.json')
         self._meta_path = join(directory, 'settingsmeta.json')
         self.is_alive = True
-        self.loaded_hash = hash(frozenset(self.items()))
+        self.loaded_hash = hash(json.dumps(self, sort_keys=True))
         self._complete_intialization = False
         self._device_identity = None
         self._api_path = None
@@ -162,7 +162,7 @@ class SkillSettings(dict):
 
     @property
     def _is_stored(self):
-        return hash(bytes(str(self), 'utf-8')) == self.loaded_hash
+        return hash(json.dumps(self, sort_keys=True)) == self.loaded_hash
 
     def __getitem__(self, key):
         """ Get key """
@@ -538,7 +538,7 @@ class SkillSettings(dict):
         if force or not self._is_stored:
             with open(self._settings_path, 'w') as f:
                 json.dump(self, f)
-            self.loaded_hash = hash(bytes(str((self)), 'utf-8'))
+            self.loaded_hash = hash(json.dumps(self, sort_keys=True))
 
         if self._should_upload_from_change:
             settings_meta = self._load_settings_meta()
-- 
2.16.2