Merge pull request #31435 from bluca/portable_fix_versioned
portable: assorted bug fixes
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
|
||||
|
||||
@@ -25,6 +25,7 @@ ImageClass image_class_from_string(const char *s) _pure_;
|
||||
* in accordance with the OS extension specification, rather than for /usr/lib/ or /etc/os-release. */
|
||||
|
||||
bool image_name_is_valid(const char *s) _pure_;
|
||||
int path_extract_image_name(const char *path, char **ret);
|
||||
|
||||
int path_is_extension_tree(ImageClass image_class, const char *path, const char *extension, bool relax_extension_release_check);
|
||||
static inline int path_is_os_tree(const char *path) {
|
||||
|
||||
Reference in New Issue
Block a user