Ensure that a portable is not detached when another portable that shares the same base is detached
The matches line includes all images, but the logic returned immediately with a successful match if the first element matches.
This commit is contained in:
+18
-16
@@ -1685,26 +1685,28 @@ static bool marker_matches_images(const char *marker, const char *name_or_path,
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
STRV_FOREACH(image_name_or_path, root_and_extensions) {
|
||||
_cleanup_free_ char *image = NULL, *base_image = NULL, *base_image_name_or_path = NULL;
|
||||
/* Ensure the number of images passed matches the number of images listed in the marker */
|
||||
while (!isempty(marker))
|
||||
STRV_FOREACH(image_name_or_path, root_and_extensions) {
|
||||
_cleanup_free_ char *image = NULL, *base_image = NULL, *base_image_name_or_path = NULL;
|
||||
|
||||
r = extract_first_word(&marker, &image, ":", EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to parse marker: %s", marker);
|
||||
if (r == 0)
|
||||
return false;
|
||||
r = extract_first_word(&marker, &image, ":", EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to parse marker: %s", marker);
|
||||
if (r == 0)
|
||||
return false;
|
||||
|
||||
r = path_extract_image_name(image, &base_image);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to extract image name from %s, ignoring: %m", image);
|
||||
r = path_extract_image_name(image, &base_image);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to extract image name from %s, ignoring: %m", image);
|
||||
|
||||
r = path_extract_image_name(*image_name_or_path, &base_image_name_or_path);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to extract image name from %s, ignoring: %m", *image_name_or_path);
|
||||
r = path_extract_image_name(*image_name_or_path, &base_image_name_or_path);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to extract image name from %s, ignoring: %m", *image_name_or_path);
|
||||
|
||||
if (!streq(base_image, base_image_name_or_path))
|
||||
return false;
|
||||
}
|
||||
if (!streq(base_image, base_image_name_or_path))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -224,6 +224,30 @@ test -f /run/systemd/system.attached/app0.service
|
||||
test -L /run/systemd/system.attached/app0.service.d/10-profile.conf
|
||||
portablectl detach --runtime --extension /usr/share/app0.raw /usr/share/minimal_0.raw app0
|
||||
|
||||
# Ensure that when two portables share the same base image, removing one doesn't remove the other too
|
||||
|
||||
portablectl "${ARGS[@]}" attach --runtime --extension /usr/share/app0.raw /usr/share/minimal_0.raw app0
|
||||
portablectl "${ARGS[@]}" attach --runtime --extension /usr/share/app1.raw /usr/share/minimal_0.raw app1
|
||||
|
||||
status="$(portablectl is-attached --extension app0 minimal_0)"
|
||||
[[ "${status}" == "attached-runtime" ]]
|
||||
status="$(portablectl is-attached --extension app1 minimal_0)"
|
||||
[[ "${status}" == "attached-runtime" ]]
|
||||
|
||||
(! portablectl detach --runtime /usr/share/minimal_0.raw app)
|
||||
|
||||
status="$(portablectl is-attached --extension app0 minimal_0)"
|
||||
[[ "${status}" == "attached-runtime" ]]
|
||||
status="$(portablectl is-attached --extension app1 minimal_0)"
|
||||
[[ "${status}" == "attached-runtime" ]]
|
||||
|
||||
portablectl detach --runtime --extension /usr/share/app0.raw /usr/share/minimal_0.raw app
|
||||
|
||||
status="$(portablectl is-attached --extension app1 minimal_0)"
|
||||
[[ "${status}" == "attached-runtime" ]]
|
||||
|
||||
portablectl detach --runtime --extension /usr/share/app1.raw /usr/share/minimal_0.raw app
|
||||
|
||||
# portablectl also works with directory paths rather than images
|
||||
|
||||
mkdir /tmp/rootdir /tmp/app0 /tmp/app1 /tmp/overlay /tmp/os-release-fix /tmp/os-release-fix/etc
|
||||
|
||||
Reference in New Issue
Block a user