Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions kiwi/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,14 @@ def which(
lookup_paths = Path.rebase_to_root(root_dir, lookup_paths)
log.debug(f"Looking for {filename} in {os.pathsep.join(lookup_paths)}")
return shutil.which(filename, access_mode, path=os.pathsep.join(lookup_paths))

@staticmethod
def first_exists(path: str) -> str:
"""
Lookup first path that exists in the given path hierarchy
"""
p = pathlib.Path(path)
if p.exists():
return path
else:
return Path.first_exists(format(p.parent))
3 changes: 2 additions & 1 deletion kiwi/runtime_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ def check_target_dir_on_unsupported_filesystem(target_dir: str) -> None:
message = dedent('''\n
Target root/image directory is lacking filesystem features

The filesystem {0} for the given image target directory {1}
The filesystem {0} in the target path {1}
does not support important features like extended permissions,
ACLs or xattrs. The image build may fail or the resulting
image misbehave.
''')
target_dir = Path.first_exists(target_dir)
stat = Command.run(['stat', '-f', '-c', '%T', target_dir])
if stat:
target_fs = stat.output.strip()
Expand Down
7 changes: 7 additions & 0 deletions test/unit/path_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,10 @@ def test_access_with_args(self, mock_access, mock_stat):

mock_stat.assert_called_once_with(fname)
mock_access.assert_called_once_with(fname, mode, effective_ids=True)

def test_first_exists(self):
assert Path.first_exists('/') == '/'
assert Path.first_exists('/etc/foo/bar') == '/etc'
assert Path.first_exists('artificial') == '.'
assert Path.first_exists('foo/bar') == '.'
assert Path.first_exists('/x/y/z') == '/'