]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
portablectl: normalize remove image paths
authordongshengyuan <545258830@qq.com>
Wed, 15 Jul 2026 08:39:16 +0000 (16:39 +0800)
committerdongshengyuan <545258830@qq.com>
Wed, 15 Jul 2026 10:16:29 +0000 (18:16 +0800)
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: 61d0578b07b97cbffebfd350bac481274e310d39

src/portable/portablectl.c
test/units/TEST-29-PORTABLE.directory.sh

index 641fc1365fc265157e3e9c73c4d84723ef3df213..27cc440437c273d62ef1248ceb2849023f615d23 100644 (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);
 
index 1cedeea72b1bcd1c6056525fa6cae968bdb824f0..a1951ee6e1fa3bebea5eb8ff8d68188f6e426a4f 100755 (executable)
@@ -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