|
@@ -4,7 +4,7 @@ import subprocess
|
|
from ._common import with_repository
|
|
from ._common import with_repository
|
|
from ..cache import Cache
|
|
from ..cache import Cache
|
|
from ..constants import * # NOQA
|
|
from ..constants import * # NOQA
|
|
-from ..helpers import prepare_subprocess_env, set_ec, CommandError
|
|
|
|
|
|
+from ..helpers import prepare_subprocess_env, set_ec, CommandError, ThreadRunner
|
|
|
|
|
|
from ..logger import create_logger
|
|
from ..logger import create_logger
|
|
|
|
|
|
@@ -15,6 +15,10 @@ class LocksMixIn:
|
|
@with_repository(manifest=False, exclusive=True)
|
|
@with_repository(manifest=False, exclusive=True)
|
|
def do_with_lock(self, args, repository):
|
|
def do_with_lock(self, args, repository):
|
|
"""run a user specified command with the repository lock held"""
|
|
"""run a user specified command with the repository lock held"""
|
|
|
|
+ # the repository lock needs to get refreshed regularly, or it will be killed as stale.
|
|
|
|
+ # refreshing the lock is not part of the repository API, so we do it indirectly via repository.info.
|
|
|
|
+ lock_refreshing_thread = ThreadRunner(sleep_interval=60, target=repository.info)
|
|
|
|
+ lock_refreshing_thread.start()
|
|
env = prepare_subprocess_env(system=True)
|
|
env = prepare_subprocess_env(system=True)
|
|
try:
|
|
try:
|
|
# we exit with the return code we get from the subprocess
|
|
# we exit with the return code we get from the subprocess
|
|
@@ -22,6 +26,8 @@ class LocksMixIn:
|
|
set_ec(rc)
|
|
set_ec(rc)
|
|
except (FileNotFoundError, OSError, ValueError) as e:
|
|
except (FileNotFoundError, OSError, ValueError) as e:
|
|
raise CommandError(f"Error while trying to run '{args.command}': {e}")
|
|
raise CommandError(f"Error while trying to run '{args.command}': {e}")
|
|
|
|
+ finally:
|
|
|
|
+ lock_refreshing_thread.terminate()
|
|
|
|
|
|
@with_repository(lock=False, manifest=False)
|
|
@with_repository(lock=False, manifest=False)
|
|
def do_break_lock(self, args, repository):
|
|
def do_break_lock(self, args, repository):
|