[dconf: 4/6] tests: Update invalidates replaced database



commit 08f7bda8af62791f88f92f0190954aa5214c779f
Author: Tomasz Miąsko <tomasz miasko gmail com>
Date:   Thu Nov 15 00:00:00 2018 +0000

    tests: Update invalidates replaced database

 tests/test-dconf.py | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
---
diff --git a/tests/test-dconf.py b/tests/test-dconf.py
index 64d3337..b277b1f 100755
--- a/tests/test-dconf.py
+++ b/tests/test-dconf.py
@@ -15,6 +15,7 @@
 # You should have received a copy of the GNU Lesser General Public
 # License along with this library; if not, see <http://www.gnu.org/licenses/>.
 
+import mmap
 import os
 import subprocess
 import sys
@@ -568,6 +569,36 @@ class DBusTest(unittest.TestCase):
 
         self.assertEqual(a_conf, dconf('dump', '/').stdout)
 
+    def test_database_invalidation(self):
+        """Update invalidates previous database by overwriting the header with
+        null bytes.
+        """
+
+        db = os.path.join(self.temporary_dir.name, 'db')
+        local = os.path.join(db, 'local')
+        local_d = os.path.join(db, 'local.d')
+
+        os.makedirs(local_d)
+
+        with open(os.path.join(local_d, 'local.conf'), 'w') as file:
+            file.write(dedent('''\
+            [org/gnome/desktop/background]
+            picture-uri = 'file:///usr/share/backgrounds/gnome/ColdWarm.jpg'
+            '''))
+
+        # Compile database for the first time.
+        dconf('update', db)
+
+        with open(local, 'rb') as file:
+            with mmap.mmap(file.fileno(), 8, mmap.MAP_SHARED, prot=mmap.PROT_READ) as mm:
+                # Sanity check that database is valid.
+                self.assertNotEqual(b'\0'*8, mm[:8])
+
+                dconf('update', db)
+
+                # Now database should be marked as invalid.
+                self.assertEqual(b'\0'*8, mm[:8])
+
 
 if __name__ == '__main__':
     # Make sure we don't pick up mandatory profile.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]