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) {
const char *start, *ext_suffix;
const char *start, *last_dot_after_underscore;
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);
@ -2231,37 +2229,41 @@ static int parse_version(const char *filename, char **ret) {
}
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");
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);
if (!version)
return -ENOMEM;
*ret = version;
return 0;
}
size_t version_length = ext_suffix - start;
if (version_length == 0) {
version = strdup("none");
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");
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;
}