os-util: allow matching versioned image with extension-release file
Currently app_1.0.raw is refused if it contains extension-release.d/extension-release.app, which stops one from using versioned images without using the force flag to disable the check. Relax it so that only the actual name, and not the version, is compared, like it already happens in other places.
This commit is contained in:
+52
-3
@@ -61,6 +61,39 @@ bool image_name_is_valid(const char *s) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int path_extract_image_name(const char *path, char **ret) {
|
||||
_cleanup_free_ char *fn = NULL;
|
||||
int r;
|
||||
|
||||
assert(path);
|
||||
assert(ret);
|
||||
|
||||
/* Extract last component from path, without any "/" suffixes. */
|
||||
r = path_extract_filename(path, &fn);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (r != O_DIRECTORY) {
|
||||
/* Chop off any image suffixes we recognize (unless we already know this must refer to some dir */
|
||||
FOREACH_STRING(suffix, ".sysext.raw", ".confext.raw", ".raw") {
|
||||
char *m = endswith(fn, suffix);
|
||||
if (m) {
|
||||
*m = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Truncate the version/counting suffixes */
|
||||
fn[strcspn(fn, "_+")] = 0;
|
||||
|
||||
if (!image_name_is_valid(fn))
|
||||
return -EINVAL;
|
||||
|
||||
*ret = TAKE_PTR(fn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int path_is_extension_tree(ImageClass image_class, const char *path, const char *extension, bool relax_extension_release_check) {
|
||||
int r;
|
||||
|
||||
@@ -230,9 +263,25 @@ int open_extension_release_at(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!relax_extension_release_check &&
|
||||
extension_release_strict_xattr_value(fd, dir_path, de->d_name) != 0)
|
||||
continue;
|
||||
if (!relax_extension_release_check) {
|
||||
_cleanup_free_ char *base_image_name = NULL, *base_extension = NULL;
|
||||
|
||||
r = path_extract_image_name(image_name, &base_image_name);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to extract image name from %s/%s, ignoring: %m", dir_path, de->d_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
r = path_extract_image_name(extension, &base_extension);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to extract image name from %s, ignoring: %m", extension);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!streq(base_image_name, base_extension) &&
|
||||
extension_release_strict_xattr_value(fd, dir_path, image_name) != 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* We already found what we were looking for, but there's another candidate? We treat this as
|
||||
* an error, as we want to enforce that there are no ambiguities in case we are in the
|
||||
|
||||
Reference in New Issue
Block a user