test: Ignore database locks if the process that locked the database no longer exists in pmtest

This commit is contained in:
Derzsi Dániel 2024-11-29 18:34:19 +02:00 committed by Disyer
parent 52996a3727
commit 32de51318d
2 changed files with 13 additions and 1 deletions

View file

@ -232,7 +232,7 @@ class pmtest(object):
return files return files
def run(self, pacman): def run(self, pacman):
if os.path.isfile(util.PM_LOCK): if util.ispacmanlocked():
tap.bail("\tERROR: another pacman session is on-going -- skipping") tap.bail("\tERROR: another pacman session is on-going -- skipping")
return return

View file

@ -184,3 +184,15 @@ def mkdir(path):
elif os.path.isfile(path): elif os.path.isfile(path):
raise OSError("'%s' already exists and is not a directory" % path) raise OSError("'%s' already exists and is not a directory" % path)
os.makedirs(path, 0o755) os.makedirs(path, 0o755)
#
# Locking
#
def ispacmanlocked():
if not os.path.exists(PM_LOCK):
return False
with open(PM_LOCK, 'r') as f:
pid = f.read().strip()
return pid.isdigit() and os.path.exists(f'/proc/{pid}')