Services: Intrusion Detection: Administration - Improve locking during sqlite db creation a bit.

If we remove the file, others will keep bashing the inode. Truncating should prevent that from happening.
This commit is contained in:
Ad Schellevis 2023-10-05 10:11:21 +02:00
parent 70df688a9b
commit 2bac4f10a5

View File

@ -243,9 +243,13 @@ class RuleCache(object):
fcntl.flock(lock, fcntl.LOCK_UN)
return
# remove existing DB
# remove (truncate) existing DB
if os.path.exists(self.cachefile):
os.remove(self.cachefile)
fhandle = open(self.cachefile, 'a+')
fhandle.seek(0)
fhandle.truncate()
fhandle.close()
db = sqlite3.connect(self.cachefile)
db.text_factory = lambda x: str(x, 'utf-8', 'ignore')