Changed lock_config to lock_client. Moved locking to run_configuration

This commit is contained in:
Andrew Burkett 2019-12-03 11:25:13 -08:00
parent 8d24b0a586
commit 4fb6a49b33
2 changed files with 9 additions and 17 deletions

View File

@ -48,6 +48,14 @@ def run_configuration(config_filename, config, arguments):
)
global_arguments = arguments['global']
if location.get("lock_client",False):
lock_f = open(config_filename)
try:
fcntl.flock(lock_f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
logger.critical("Failed to acquire lock for {}".format(config_filename))
sys.exit(1)
local_path = location.get('local_path', 'borg')
remote_path = location.get('remote_path')
borg_environment.initialize(storage)
@ -567,25 +575,9 @@ def main(): # pragma: no cover
logger.debug('Ensuring legacy configuration is upgraded')
convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames)
locks = []
for config_filename,config in configs.items():
lock_config = config.get("location",dict()).get("lock_config",False)
if lock_config:
f = open(config_filename)
try:
fcntl.flock(f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
logger.critical("Failed to acquire lock for {}".format(config_filename))
sys.exit(0)
locks.append(f)
summary_logs = parse_logs + list(collect_configuration_run_summary_logs(configs, arguments))
summary_logs_max_level = max(log.levelno for log in summary_logs)
# this removes the reference to the open files which python will garbage collect the file objects
# and close them
locks = None
for message in ('', 'summary:'):
log_record(
levelno=summary_logs_max_level,

View File

@ -32,7 +32,7 @@ map:
type: bool
desc: Stay in same file system (do not cross mount points). Defaults to false.
example: true
lock_config:
lock_client:
type: bool
desc: Lock config when running borgmatic to prevent multiple instances from running simultaneously
example: true