Fix various issues in the distro validation script (#41141)
Blue committed
Jul 23, 2026 at 13:37 UTC
ba177f09e066b784e24dd21da7967e20a2a6e1d3
1 file changed
+28
-13
distributions/validate-modern.py
+28
-13
@@ -31,6 +31,7 @@ DISCOURAGED_SYSTEM_UNITS = ['systemd-resolved.service',
31
'systemd-tmpfiles-clean.service',
32
'systemd-tmpfiles-setup-dev-early.service',
33
'systemd-tmpfiles-setup-dev.service',
34
+ 'systemd-vconsole-setup.service',
35
'tmp.mount',
36
'NetworkManager.service',
37
'NetworkManager-wait-online.service',
@@ -239,26 +240,40 @@ def read_systemd_enabled_units(node, tar) -> dict:
240
all_files = tar.getnames()
241
242
def link_target(unit_path: str):
242
- try:
243
- info = tar.getmember(unit_path)
244
- except KeyError:
245
- info = tar.getmember('.' + unit_path)
243
+ info = get_tar_file(tar, unit_path, follow_symlink=False)[0]
244
+ if info is None:
245
+ raise KeyError(unit_path)
246
247
if not info.issym():
248
return unit_path
249
+
250
+ if info.linkpath.startswith('/'):
251
+ resolved = linux_real_path(info.linkpath)
252
else:
250
- if info.linkpath.startswith('/'):
251
- return get_tar_file(tar, linux_real_path(info.linkpath), follow_symlink=True)[1]
252
- else:
253
- return get_tar_file(tar, linux_real_path(os.path.dirname(unit_path) + '/' + info.linkpath), follow_symlink=True)[1]
253
+ resolved = linux_real_path(os.path.dirname(unit_path) + '/' + info.linkpath)
254
+
255
+ real = get_tar_file(tar, resolved, follow_symlink=True)[1]
256
+ if real is not None:
257
+ return real
258
+
259
+ return resolved if resolved.startswith('/') else '/' + resolved
260
261
def list_directory(path: str):
262
+ prefix = path.strip('/')
263
files = []
264
for e in all_files:
258
- if e.startswith(path):
259
- files.append(e[len(path) + 1:])
260
- elif e.startswith('.' + path):
261
- files.append(e[len(path) + 2:])
265
+ normalized = e
266
+ if normalized.startswith('./'):
267
+ normalized = normalized[2:]
268
+ elif normalized.startswith('/'):
269
+ normalized = normalized[1:]
270
+ normalized = normalized.rstrip('/')
271
+
272
+ if normalized == prefix:
273
+ continue # The directory itself, not an entry within it
274
+
275
+ if normalized.startswith(prefix + '/'):
276
+ files.append(normalized[len(prefix) + 1:])
277
278
return files
279
@@ -283,7 +298,7 @@ def read_systemd_enabled_units(node, tar) -> dict:
298
299
unit_target = link_target(fullpath)
300
286
- if is_dev_null(unit_target) and not is_masked(e):
301
+ if not is_dev_null(unit_target) and not is_masked(e):
302
units[e] = fullpath
303
304
return units