Compare commits

..

2 Commits

Author SHA1 Message Date
Maanya Goenka a539bec5f4
Merge f3a9cb423e into c946b13575 2024-11-23 02:40:16 +08:00
Maanya Goenka f3a9cb423e 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-21 18:48:57 +00:00
1 changed files with 25 additions and 23 deletions

View File

@ -2210,10 +2210,8 @@ static int vl_method_refresh(sd_varlink *link, sd_json_variant *parameters, sd_v
} }
static int parse_version(const char *filename, char **ret) { static int parse_version(const char *filename, char **ret) {
const char *start, *ext_suffix; const char *start, *last_dot_after_underscore;
char *version = NULL; 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(filename);
assert(ret); assert(ret);
@ -2231,37 +2229,41 @@ static int parse_version(const char *filename, char **ret) {
} }
start ++; start ++;
/* Find the extension suffix, if a valid one is associated with it */ last_dot_after_underscore = strrchr(start, '.');
for (const char **ext = valid_extensions; *ext; ++ext) { if (!last_dot_after_underscore || (*(last_dot_after_underscore + 1) == '\0')) {
ext_suffix = strstr(start, *ext); /* If no dot found or if dot is the last character, treat everything
if (ext_suffix) / after '_' as the version */
break; version = strdup(start);
}
if (!ext_suffix) {
/* If no valid extension filename suffix is found, assign "none" and return success. */
version = strdup("none");
if (!version) if (!version)
return -ENOMEM; return -ENOMEM;
*ret = version; *ret = version;
return 0; return 0;
} }
size_t version_length = ext_suffix - start; if (last_dot_after_underscore[1] && isdigit(last_dot_after_underscore[1])) {
if (version_length == 0) { /* If the last dot is followed by a digit, the version is everything after the underscore
version = strdup("none"); * 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");
if (!version) if (!version)
return -ENOMEM; return -ENOMEM;
*ret = version; *ret = version;
return 0;
} }
/* Extract the version substring */
version = strndup(start, version_length);
if (!version)
return -ENOMEM;
*ret = version;
return 0; return 0;
} }