Skip to content

Commit

Permalink
locking: generalize locking to all included files
Browse files Browse the repository at this point in the history
Previously, kas only checked if a lockfile exists for the first file on
the kas commandline. This is problematic when injecting mirror
configurations by appending the site config as last file. In addition,
it makes it hard for projects with multiple configs (kas-files) to use
the locking support.

This patch removes this limitation by checking for each file for a
corresponding lock file. Hereby the same depths-first search logic is
applied as with kas includes. Each lockfile is added as it would be the
next include to process, i.e. after descending into the current
hierarchie. This is applied recursively.

Signed-off-by: Felix Moessbauer <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
fmoessbauer authored and jan-kiszka committed Oct 22, 2023
1 parent af82e38 commit ddb9217
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
7 changes: 4 additions & 3 deletions docs/userguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,10 @@ KAS supports the use of lockfiles to pinpoint repositories to exact commit ID
(e.g. SHA-1 refs for git). A lockfile hereby only overrides the commit ID
defined in a kas file. When performing the checkout operation (or any other
operation that performs a checkout), kas checks if a file named
``<filename>.lock.<ext>`` is found next to the first file stated on the kas
cmdline. If this is found, kas appends this filename to the kas cmdline and
performs the requested operation.
``<filename>.lock.<ext>`` is found next to the currently processed kas file.
If this is found, kas loads this file right after processing the current one.
Note, that this applies to both files on the kas cmdline, as well as included
files.

The following example shows this mechanism for a file ``kas/kas-isar.yml``
and its corresponding lockfile ``kas/kas-isar.lock.yml``.
Expand Down
19 changes: 11 additions & 8 deletions kas/includehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,10 @@ class IncludeHandler:
def __init__(self, top_files, top_repo_path, use_lock=True):
self.top_files = top_files
self.top_repo_path = top_repo_path
self.use_lock = use_lock

if use_lock:
lockfile = self.get_lockfile()
if Path(lockfile).exists():
logging.debug('includehandler: append lockfile %s', lockfile)
self.top_files.append(lockfile)

def get_lockfile(self):
file = Path(self.top_files[0])
def get_lockfile(self, kasfile=None):
file = Path(kasfile or self.top_files[0])
return file.parent / (file.stem + '.lock' + file.suffix)

def get_top_repo_path(self):
Expand Down Expand Up @@ -195,6 +190,14 @@ def _internal_include_handler(filename, repo_path):
configs = []
try:
current_config, src_dir = load_config(filename)
# if lockfile exists and locking, inject it after current file
lockfile = self.get_lockfile(filename)
if self.use_lock and Path(lockfile).exists():
logging.debug('append lockfile %s', lockfile)
(cfg, rep) = _internal_include_handler(lockfile,
repo_path)
configs.extend(cfg)
missing_repos.extend(rep)
# src_dir must only be set by auto-generated config file
if src_dir:
self.top_repo_path = src_dir
Expand Down

0 comments on commit ddb9217

Please sign in to comment.