shared: add new "vpick" concept for ".v/" directories that contain versioned resources
authorLennart Poettering <lennart@poettering.net>
Fri, 3 Mar 2023 17:18:05 +0000 (18:18 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 3 Jan 2024 17:38:46 +0000 (18:38 +0100)
commit76511c1bd32a262c76d462919083925c47cbd212
treeb33e25999938371180789956a73e9505aeb77a5f
parentcc03788086e4c02d8e1f44cc84e0536594cca230
shared: add new "vpick" concept for ".v/" directories that contain versioned resources

This adds a new concept for handling paths. At appropriate places, if a
path such as /foo/bar/baz.v/ is specified, we'll
automatically enumerate all entries in /foo/bar/baz.v/baz* and then
do a version sort and pick the newest file.

A slightly more complex syntax is available, too:

/foo/bar/baz.v/quux___waldo

if that's used, then we'll look for all files matching
/foo/bar/baz.v/quux*waldo, and split out the middle, and version sort
it, and pick the nwest.

The ___ wildcard indicates both a version string, and if needed an
architecture ID, in case per-arch entries shall be supported.

This is a very simple way to maintain versioned resources in a dir, and
make systemd's components automatically pick the newest. Example:

    /srv/myimages.v/foobar_1.32.65_x86-64.raw
    /srv/myimages.v/foobar_1.33.45_x86-64.raw
    /srv/myimages.v/foobar_1.31.5_x86-64.raw
    /srv/myimages.v/foobar_1.31.5_arm64.raw

If now nspawn is invoked like this:

    systemd-nspawn --image=/srv/myimages.v/foobar___.raw

Then it will automatically pick
/srv/myimages.v/foobar_1.33.45_x86-64.raw as the version to boot on
x86-64, and /srv/myimages.v/foobar_1.31.5_arm64.raw on arm64.

This commit only adds the basic implementation for picking files from a
dir, but no hook-up anywhere.
src/shared/meson.build
src/shared/vpick.c [new file with mode: 0644]
src/shared/vpick.h [new file with mode: 0644]
src/test/meson.build
src/test/test-vpick.c [new file with mode: 0644]