Set secure_delete pragma for SQLite3 connections

secure_delete makes SQLite3 overwrite deleted data with zeros, thus actually deleting it from the filesystem.

Ubuntu and FreeBSD enable it by defualt, but some distributions, such as Debian, have it disabled by default, so it is better to set it explicitly.

The performance impact should be negligible as Gajim uses the database rarely.
This commit is contained in:
Alexander Krotov 2018-06-12 23:34:28 +03:00 committed by Philipp Hörist
parent e20f044001
commit 22d799a75e
2 changed files with 12 additions and 5 deletions

View File

@ -158,9 +158,15 @@ class Logger:
self._create(CACHE_SQL_STATEMENT, self._cache_db_path) self._create(CACHE_SQL_STATEMENT, self._cache_db_path)
@staticmethod @staticmethod
def _create(statement, path): def _connect(*args, **kwargs):
con = sqlite.connect(*args, **kwargs)
con.execute("PRAGMA secure_delete=1")
return con
@classmethod
def _create(cls, statement, path):
log.info(_('Creating %s'), path) log.info(_('Creating %s'), path)
con = sqlite.connect(path) con = cls._connect(path)
os.chmod(path, 0o600) os.chmod(path, 0o600)
try: try:
@ -181,11 +187,11 @@ class Logger:
def _migrate_databases(self): def _migrate_databases(self):
try: try:
con = sqlite.connect(self._log_db_path) con = self._connect(self._log_db_path)
self._migrate_logs(con) self._migrate_logs(con)
con.close() con.close()
con = sqlite.connect(self._cache_db_path) con = self._connect(self._cache_db_path)
self._migrate_cache(con) self._migrate_cache(con)
con.close() con.close()
except Exception: except Exception:
@ -272,7 +278,7 @@ class Logger:
app.ged.raise_event(event, None, str(error)) app.ged.raise_event(event, None, str(error))
def _connect_databases(self): def _connect_databases(self):
self._con = sqlite.connect( self._con = self._connect(
self._log_db_path, timeout=20.0, isolation_level='IMMEDIATE') self._log_db_path, timeout=20.0, isolation_level='IMMEDIATE')
self._con.row_factory = self.namedtuple_factory self._con.row_factory = self.namedtuple_factory

View File

@ -131,6 +131,7 @@ class HistoryManager:
self.con = sqlite3.connect( self.con = sqlite3.connect(
log_db_path, timeout=20.0, isolation_level='IMMEDIATE') log_db_path, timeout=20.0, isolation_level='IMMEDIATE')
self.con.execute("PRAGMA secure_delete=1")
self.cur = self.con.cursor() self.cur = self.con.cursor()
self._init_jids_listview() self._init_jids_listview()