mirror of
https://github.com/systemd/systemd.git
synced 2025-03-13 00:58:27 +03:00
portable: allow reattaching when one image has a version and the other does not
A reattach might go from img.raw to img_0.1.raw or viceversa, but this is not allowed right now as we try to match the full name. Also take into account that running strcspn(a, '/') on an image name, without leading path, will return the length of the full string, but the versions might be different so they won't match, eg: img_0.1.raw -> 12 img_0.1.1.raw -> 14 So adjust the check to take that into account, and skip it if we are not dealing with directories
This commit is contained in:
parent
f09f6dc2c8
commit
2350712e32
@ -1429,17 +1429,28 @@ static bool marker_matches_images(const char *marker, const char *name_or_path,
|
||||
size_t l;
|
||||
|
||||
/* We shall match against a path. Let's ignore any prefix here though, as often there are many ways to
|
||||
* reach the same file. However, in this mode, let's validate any file suffix. */
|
||||
* reach the same file. However, in this mode, let's validate any file suffix.
|
||||
* But also ensure that we don't fail if both components don't have a '/' at all
|
||||
* (strcspn returns the full length of the string in that case, which might not
|
||||
* match as the versions might differ). */
|
||||
|
||||
l = strcspn(a, "/");
|
||||
b = last_path_component(*image_name_or_path);
|
||||
|
||||
if (strcspn(b, "/") != l)
|
||||
if ((a[l] != '/') != !strchr(b, '/')) /* One is a directory, the other is not */
|
||||
return false;
|
||||
|
||||
if (a[l] != 0 && strcspn(b, "/") != l)
|
||||
return false;
|
||||
|
||||
underscore = strchr(b, '_');
|
||||
if (underscore)
|
||||
l = underscore - b;
|
||||
else { /* Either component could be versioned */
|
||||
underscore = strchr(a, '_');
|
||||
if (underscore)
|
||||
l = underscore - a;
|
||||
}
|
||||
|
||||
if (!strneq(a, b, l))
|
||||
return false;
|
||||
|
@ -88,6 +88,14 @@ systemctl is-active app1.service
|
||||
status="$(portablectl is-attached --extension app1 minimal_0)"
|
||||
[[ "${status}" == "running-runtime" ]]
|
||||
|
||||
# Ensure that adding or removing a version to the image doesn't break reattaching
|
||||
cp /usr/share/app1.raw /tmp/app1_2.raw
|
||||
portablectl "${ARGS[@]}" reattach --now --runtime --extension /tmp/app1_2.raw /usr/share/minimal_1.raw app1
|
||||
|
||||
systemctl is-active app1.service
|
||||
status="$(portablectl is-attached --extension app1_2 minimal_1)"
|
||||
[[ "${status}" == "running-runtime" ]]
|
||||
|
||||
portablectl "${ARGS[@]}" reattach --now --runtime --extension /usr/share/app1.raw /usr/share/minimal_1.raw app1
|
||||
|
||||
systemctl is-active app1.service
|
||||
|
Loading…
x
Reference in New Issue
Block a user