Compare commits
2 Commits
a539bec5f4
...
e89a00c6bd
Author | SHA1 | Date |
---|---|---|
Maanya Goenka | e89a00c6bd | |
Maanya Goenka | 0eb25fafc8 |
|
@ -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) {
|
static int parse_version(const char *filename, char **ret) {
|
||||||
const char *start, *last_dot_after_underscore;
|
const char *start, *ext_suffix;
|
||||||
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);
|
||||||
|
@ -2229,41 +2231,37 @@ static int parse_version(const char *filename, char **ret) {
|
||||||
}
|
}
|
||||||
start ++;
|
start ++;
|
||||||
|
|
||||||
last_dot_after_underscore = strrchr(start, '.');
|
/* Find the extension suffix, if a valid one is associated with it */
|
||||||
if (!last_dot_after_underscore || (*(last_dot_after_underscore + 1) == '\0')) {
|
for (const char **ext = valid_extensions; *ext; ++ext) {
|
||||||
/* If no dot found or if dot is the last character, treat everything
|
ext_suffix = strstr(start, *ext);
|
||||||
/ after '_' as the version */
|
if (ext_suffix)
|
||||||
version = strdup(start);
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last_dot_after_underscore[1] && isdigit(last_dot_after_underscore[1])) {
|
size_t version_length = ext_suffix - start;
|
||||||
/* If the last dot is followed by a digit, the version is everything after the underscore
|
if (version_length == 0) {
|
||||||
* This is for cases where the extension name is like so: image_0.1 */
|
version = strdup("none");
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue