portablectl: normalize remove image paths

Normalize each remove argument with determine_image() before building
the RemoveImage request. Relative paths are converted before reaching
portabled.

Reproducer:
  cd /tmp
  portablectl remove ./portable-repro

Before:
  ./portable-repro was sent unchanged to portabled and rejected as an
  invalid image name/path. Removing an image by a relative path failed
  even though the path referred to a valid local image.

Follow-up: 61d0578b07
This commit is contained in:
dongshengyuan
2026-07-15 18:16:29 +08:00
parent 797dd11524
commit 018c2b229f
2 changed files with 11 additions and 1 deletions
+6 -1
View File
@@ -1440,12 +1440,17 @@ static int verb_remove_image(int argc, char *argv[], uintptr_t _data, void *user
for (i = 1; i < argc; i++) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_free_ char *image = NULL;
r = determine_image(argv[i], false, &image);
if (r < 0)
return r;
r = bus_message_new_method_call(bus, &m, bus_portable_mgr, "RemoveImage");
if (r < 0)
return bus_log_create_error(r);
r = sd_bus_message_append(m, "s", argv[i]);
r = sd_bus_message_append(m, "s", image);
if (r < 0)
return bus_log_create_error(r);
+5
View File
@@ -24,6 +24,11 @@ rm -rf /tmp/mismatched-name
cp -a /tmp/minimal_0 /tmp/mismatched-name
portablectl inspect /tmp/mismatched-name | grep -F "minimal-app0.service" >/dev/null
rm -rf /tmp/remove-relative
cp -a /tmp/minimal_0 /tmp/remove-relative
(cd /tmp && portablectl remove ./remove-relative)
test ! -e /tmp/remove-relative
rm -rf /tmp/symlink-unit
cp -a /tmp/minimal_0 /tmp/symlink-unit
printf '[Service]\nExecStart=/bin/true\n' >/tmp/portable-host-unit