Compare commits

..

2 Commits

Author SHA1 Message Date
Maanya Goenka e89a00c6bd
Merge 0eb25fafc8 into c946b13575 2024-11-23 00:58:43 +01:00
Maanya Goenka 0eb25fafc8 Add version as new column in the list command table output
Add a new column in the list command output table that logs the version of the image name of the extension.
'version' of the image should be the part of the image name string that includes the version and the boot counters
at the end of the filename but excludes the .raw type suffix. This commit modifies the table outputted by the list
command to have the version from the absolute filename displayed alongside the shortened image name.
2024-11-22 23:58:34 +00:00
1 changed files with 23 additions and 25 deletions

View File

@ -2210,8 +2210,10 @@ static int vl_method_refresh(sd_varlink *link, sd_json_variant *parameters, sd_v
}
static int parse_version(const char *filename, char **ret) {
const char *start, *last_dot_after_underscore;
const char *start, *ext_suffix;
char *version = NULL;
/* We are only looking for extension images here, because for directories, we want a no-op*/
static const char *valid_extensions[] = {".confext.raw", ".sysext.raw", ".raw"};
assert(filename);
assert(ret);
@ -2229,41 +2231,37 @@ static int parse_version(const char *filename, char **ret) {
}
start ++;
last_dot_after_underscore = strrchr(start, '.');
if (!last_dot_after_underscore || (*(last_dot_after_underscore + 1) == '\0')) {
/* If no dot found or if dot is the last character, treat everything
/ after '_' as the version */
version = strdup(start);
/* Find the extension suffix, if a valid one is associated with it */
for (const char **ext = valid_extensions; *ext; ++ext) {
ext_suffix = strstr(start, *ext);
if (ext_suffix)
break;
}
if (!ext_suffix) {
/* If no valid extension filename suffix is found, assign "none" and return success. */
version = strdup("none");
if (!version)
return -ENOMEM;
*ret = version;
return 0;
}
if (last_dot_after_underscore[1] && isdigit(last_dot_after_underscore[1])) {
/* If the last dot is followed by a digit, the version is everything after the underscore
* This is for cases where the extension name is like so: image_0.1 */
version = strdup(start);
if (!version)
return -ENOMEM;
*ret = version;
} else if (last_dot_after_underscore[1] && isalpha(last_dot_after_underscore[1])) {
/* If the last dot is followed by a letter, the version is between the first '_' and the last dot
* This is for cases where the extension name is like so: image_0.1.raw (version is 0.1)
* or image_1.raw (version is 1) */
size_t length = last_dot_after_underscore - start;
version = strndup(start, length);
if (!version)
return -ENOMEM;
*ret = version;
} else {
/* In all other cases assign "n/a" to version */
version = strdup("n/a");
size_t version_length = ext_suffix - start;
if (version_length == 0) {
version = strdup("none");
if (!version)
return -ENOMEM;
*ret = version;
return 0;
}
/* Extract the version substring */
version = strndup(start, version_length);
if (!version)
return -ENOMEM;
*ret = version;
return 0;
}