return 0;
}
-static int attach_extensions_to_message(sd_bus_message *m, char **extensions) {
+static int attach_extensions_to_message(sd_bus_message *m, const char *method, char **extensions) {
int r;
assert(m);
+ assert(method);
- if (strv_isempty(extensions))
+ /* The new methods also have flags parameters that are independent of the extensions */
+ if (strv_isempty(extensions) && !endswith(method, "WithExtensions"))
return 0;
r = sd_bus_message_open_container(m, 'a', "s");
if (r < 0)
return bus_log_create_error(r);
- r = attach_extensions_to_message(m, arg_extension_images);
+ r = attach_extensions_to_message(m, method, arg_extension_images);
if (r < 0)
return r;
if (r < 0)
return bus_log_create_error(r);
- if (!strv_isempty(arg_extension_images)) {
+ if (streq(method, "GetImageMetadataWithExtensions")) {
r = sd_bus_message_append(m, "t", flags);
if (r < 0)
return bus_log_create_error(r);
if (r < 0)
return bus_log_parse_error(r);
- /* If we specified any extensions, we'll first an array of extension-release metadata. */
- if (!strv_isempty(arg_extension_images)) {
+ /* If we specified any extensions or --force (which makes the request go through the new
+ * WithExtensions calls), we'll first get an array of extension-release metadata. */
+ if (!strv_isempty(arg_extension_images) || arg_force) {
r = sd_bus_message_skip(reply, "a{say}");
if (r < 0)
return bus_log_parse_error(r);
if (r < 0)
return bus_log_create_error(r);
- r = attach_extensions_to_message(m, arg_extension_images);
+ r = attach_extensions_to_message(m, method, arg_extension_images);
if (r < 0)
return r;
if (r < 0)
return bus_log_create_error(r);
- r = attach_extensions_to_message(m, arg_extension_images);
+ r = attach_extensions_to_message(m, method, arg_extension_images);
if (r < 0)
return r;
- if (strv_isempty(arg_extension_images))
+ if (streq(method, "DetachImage"))
r = sd_bus_message_append(m, "b", arg_runtime);
else {
uint64_t flags = (arg_runtime ? PORTABLE_RUNTIME : 0) | (arg_force ? PORTABLE_FORCE_ATTACH | PORTABLE_FORCE_SYSEXT : 0);
if (r < 0)
return bus_log_create_error(r);
- r = attach_extensions_to_message(m, arg_extension_images);
+ r = attach_extensions_to_message(m, method, arg_extension_images);
if (r < 0)
return r;
portablectl "${ARGS[@]}" attach --now --runtime /usr/share/minimal_0.raw minimal-app0
+portablectl is-attached minimal-app0
+portablectl inspect /usr/share/minimal_0.raw minimal-app0.service
systemctl is-active minimal-app0.service
systemctl is-active minimal-app0-foo.service
systemctl is-active minimal-app0-bar.service && exit 1
portablectl "${ARGS[@]}" reattach --now --runtime /usr/share/minimal_1.raw minimal-app0
+portablectl is-attached minimal-app0
+portablectl inspect /usr/share/minimal_0.raw minimal-app0.service
systemctl is-active minimal-app0.service
systemctl is-active minimal-app0-bar.service
systemctl is-active minimal-app0-foo.service && exit 1
portablectl list | grep -q -F "No images."
busctl tree org.freedesktop.portable1 --no-pager | grep -q -F '/org/freedesktop/portable1/image/minimal_5f1' && exit 1
+# Ensure we don't regress (again) when using --force
+
+portablectl "${ARGS[@]}" attach --force --now --runtime /usr/share/minimal_0.raw minimal-app0
+
+portablectl is-attached --force minimal-app0
+portablectl inspect --force /usr/share/minimal_0.raw minimal-app0.service
+systemctl is-active minimal-app0.service
+systemctl is-active minimal-app0-foo.service
+systemctl is-active minimal-app0-bar.service && exit 1
+
+portablectl "${ARGS[@]}" reattach --force --now --runtime /usr/share/minimal_1.raw minimal-app0
+
+portablectl is-attached --force minimal-app0
+portablectl inspect --force /usr/share/minimal_0.raw minimal-app0.service
+systemctl is-active minimal-app0.service
+systemctl is-active minimal-app0-bar.service
+systemctl is-active minimal-app0-foo.service && exit 1
+
+portablectl list | grep -q -F "minimal_1"
+busctl tree org.freedesktop.portable1 --no-pager | grep -q -F '/org/freedesktop/portable1/image/minimal_5f1'
+
+portablectl detach --force --now --runtime /usr/share/minimal_1.raw minimal-app0
+
+portablectl list | grep -q -F "No images."
+busctl tree org.freedesktop.portable1 --no-pager | grep -q -F '/org/freedesktop/portable1/image/minimal_5f1' && exit 1
+
# portablectl also works with directory paths rather than images
unsquashfs -dest /tmp/minimal_0 /usr/share/minimal_0.raw