machine: generalize rename_image_and_update_cache() logic

This is a prep step to reuse the function in varlink interface
This commit is contained in:
Ivan Kruglov
2024-10-14 10:42:47 +02:00
parent ad0d4f9a4c
commit dd2d5952c9
3 changed files with 30 additions and 11 deletions
+3 -11
View File
@@ -127,17 +127,9 @@ int bus_image_method_rename(
if (r == 0)
return 1; /* Will call us back */
/* The image is cached with its name, hence it is necessary to remove from the cache before renaming. */
assert_se(hashmap_remove_value(m->image_cache, image->name, image));
r = image_rename(image, new_name);
if (r < 0) {
image_unref(image);
return r;
}
/* Then save the object again in the cache. */
assert_se(hashmap_put(m->image_cache, image->name, image) > 0);
r = rename_image_and_update_cache(m, image, new_name);
if (r < 0)
return sd_bus_error_set_errnof(error, r, "Failed to rename image: %m");
return sd_bus_reply_method_return(message, NULL);
}