@@ -52,6 +52,9 @@ def __init__(self):
5252 self .__db_file = os .path .join (
5353 osext .expandvars (runtime ().get_option ('storage/0/sqlite_db_file' ))
5454 )
55+ self .__db_file_mode = runtime ().get_option (
56+ 'storage/0/sqlite_db_file_mode'
57+ )
5558
5659 def _db_file (self ):
5760 prefix = os .path .dirname (self .__db_file )
@@ -78,6 +81,11 @@ def _db_connect(self, *args, **kwargs):
7881 with getprofiler ().time_region ('sqlite connect' ):
7982 return sqlite3 .connect (* args , ** kwargs )
8083
84+ def _db_lock (self ):
85+ prefix = os .path .dirname (self .__db_file )
86+ return FileLock (os .path .join (prefix , '.db.lock' ),
87+ mode = self .__db_file_mode )
88+
8189 def _db_create (self ):
8290 clsname = type (self ).__name__
8391 getlogger ().debug (
@@ -104,6 +112,8 @@ def _db_create(self):
104112 'on testcases(job_completion_time_unix)' )
105113 conn .execute ('CREATE TABLE IF NOT EXISTS metadata('
106114 'schema_version TEXT)' )
115+ # Update DB file mode
116+ os .chmod (self .__db_file , self .__db_file_mode )
107117
108118 def _db_schema_check (self ):
109119 with self ._db_connect (self .__db_file ) as conn :
@@ -164,9 +174,8 @@ def _db_store_report(self, conn, report, report_file_path):
164174 return session_uuid
165175
166176 def store (self , report , report_file = None ):
167- prefix = os .path .dirname (self .__db_file )
168177 with self ._db_connect (self ._db_file ()) as conn :
169- with FileLock ( os . path . join ( prefix , '.db.lock' ) ):
178+ with self . _db_lock ( ):
170179 return self ._db_store_report (conn , report , report_file )
171180
172181 @time_function
@@ -298,8 +307,7 @@ def fetch_session_json(self, uuid):
298307 return jsonext .loads (results [0 ][0 ]) if results else {}
299308
300309 def _do_remove (self , uuid ):
301- prefix = os .path .dirname (self .__db_file )
302- with FileLock (os .path .join (prefix , '.db.lock' )):
310+ with self ._db_lock ():
303311 with self ._db_connect (self ._db_file ()) as conn :
304312 # Enable foreign keys for delete action to have cascade effect
305313 conn .execute ('PRAGMA foreign_keys = ON' )
@@ -316,8 +324,7 @@ def _do_remove(self, uuid):
316324
317325 def _do_remove2 (self , uuid ):
318326 '''Remove a session using the RETURNING keyword'''
319- prefix = os .path .dirname (self .__db_file )
320- with FileLock (os .path .join (prefix , '.db.lock' )):
327+ with self ._db_lock ():
321328 with self ._db_connect (self ._db_file ()) as conn :
322329 # Enable foreign keys for delete action to have cascade effect
323330 conn .execute ('PRAGMA foreign_keys = ON' )
0 commit comments