mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-09-04 20:51:31 +00:00
Show the real latest version using check-update
When running the check-update command we get the latest version for the format we are currently in, but we really want to get the latest version regardless of the format. This commit fixes the issue. Closes #482 Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit is contained in:
committed by
Otavio Pontes
parent
f19e8dce06
commit
a41bea9fd5
@@ -213,6 +213,7 @@ BATS = \
|
||||
test/functional/bundleremove/remove-parse-args.bats \
|
||||
test/functional/bundleremove/remove-with-dependency.bats \
|
||||
test/functional/checkupdate/chk-update-client-certificate.bats \
|
||||
test/functional/checkupdate/chk-update-format-bump.bats \
|
||||
test/functional/checkupdate/chk-update-json.bats \
|
||||
test/functional/checkupdate/chk-update-new-version.bats \
|
||||
test/functional/checkupdate/chk-update-no-server-content.bats \
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ enum swupd_code check_update()
|
||||
int current_version, server_version;
|
||||
enum swupd_code ret;
|
||||
|
||||
ret = read_versions(¤t_version, &server_version, globals.path_prefix);
|
||||
ret = read_versions(¤t_version, &server_version, globals.path_prefix, true);
|
||||
|
||||
if (current_version > 0) {
|
||||
info("Current OS version: %d\n", current_version);
|
||||
|
||||
+2
-1
@@ -161,7 +161,8 @@ extern int main_verify(int current_version);
|
||||
extern enum swupd_code walk_tree(struct manifest *, const char *, bool, const regex_t *, struct file_counts *);
|
||||
|
||||
extern int get_latest_version(char *v_url);
|
||||
extern enum swupd_code read_versions(int *current_version, int *server_version, char *path_prefix);
|
||||
extern int get_absolute_latest_version(void);
|
||||
extern enum swupd_code read_versions(int *current_version, int *server_version, char *path_prefix, bool absolute);
|
||||
extern int get_current_version(char *path_prefix);
|
||||
extern bool get_distribution_string(char *path_prefix, char *dist);
|
||||
|
||||
|
||||
+1
-1
@@ -203,7 +203,7 @@ static enum swupd_code check_versions(int *current_version, int *server_version,
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = read_versions(current_version, server_version, path_prefix);
|
||||
ret = read_versions(current_version, server_version, path_prefix, false);
|
||||
if (ret != SWUPD_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
+49
-25
@@ -31,6 +31,33 @@
|
||||
#include "config.h"
|
||||
#include "swupd.h"
|
||||
|
||||
static int get_version_from_url(char *url)
|
||||
{
|
||||
#define MAX_VERSION_STR_SIZE 11
|
||||
|
||||
int ret;
|
||||
int err;
|
||||
char version_str[MAX_VERSION_STR_SIZE];
|
||||
struct curl_file_data tmp_version = {
|
||||
MAX_VERSION_STR_SIZE, 0,
|
||||
version_str
|
||||
};
|
||||
|
||||
ret = swupd_curl_get_file_memory(url, &tmp_version);
|
||||
if (ret) {
|
||||
goto out;
|
||||
} else {
|
||||
tmp_version.data[tmp_version.len] = '\0';
|
||||
err = strtoi_err(tmp_version.data, &ret);
|
||||
if (err != 0) {
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* this function attempts to download the latest server version string file from
|
||||
* the preferred server to a memory buffer, returning either a negative integer
|
||||
* error code or >= 0 representing the server version
|
||||
@@ -41,17 +68,8 @@
|
||||
* the global version_url is used and the cached version is ignored. */
|
||||
int get_latest_version(char *v_url)
|
||||
{
|
||||
#define MAX_VERSION_CHARS 10
|
||||
#define MAX_VERSION_STR_SIZE 11
|
||||
|
||||
char *url = NULL;
|
||||
int ret = 0;
|
||||
int err;
|
||||
char version_str[MAX_VERSION_STR_SIZE];
|
||||
struct curl_file_data tmp_version = {
|
||||
MAX_VERSION_STR_SIZE, 0,
|
||||
version_str
|
||||
};
|
||||
static int cached_version = -1;
|
||||
|
||||
if (cached_version > 0 && v_url == NULL) {
|
||||
@@ -63,22 +81,24 @@ int get_latest_version(char *v_url)
|
||||
}
|
||||
|
||||
string_or_die(&url, "%s/version/format%s/latest", v_url, globals.format_string);
|
||||
|
||||
ret = swupd_curl_get_file_memory(url, &tmp_version);
|
||||
if (ret) {
|
||||
goto out;
|
||||
} else {
|
||||
tmp_version.data[tmp_version.len] = '\0';
|
||||
err = strtoi_err(tmp_version.data, &ret);
|
||||
|
||||
if (err != 0) {
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
ret = get_version_from_url(url);
|
||||
free_string(&url);
|
||||
cached_version = ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* gets the latest version of the update content regardless of what format we
|
||||
* are currently in */
|
||||
int version_get_absolute_latest(void)
|
||||
{
|
||||
char *url = NULL;
|
||||
int ret;
|
||||
|
||||
string_or_die(&url, "%s/version/latest_version", globals.version_url);
|
||||
ret = get_version_from_url(url);
|
||||
free_string(&url);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -175,10 +195,14 @@ bool get_distribution_string(char *path_prefix, char *dist)
|
||||
return true;
|
||||
}
|
||||
|
||||
enum swupd_code read_versions(int *current_version, int *server_version, char *path_prefix)
|
||||
enum swupd_code read_versions(int *current_version, int *server_version, char *path_prefix, bool absolute)
|
||||
{
|
||||
*current_version = get_current_version(path_prefix);
|
||||
*server_version = get_latest_version(NULL);
|
||||
if (absolute) {
|
||||
*server_version = version_get_absolute_latest();
|
||||
} else {
|
||||
*server_version = get_latest_version(NULL);
|
||||
}
|
||||
|
||||
if (*current_version < 0) {
|
||||
error("Unable to determine current OS version\n");
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
# Author: Castulo Martinez
|
||||
# Email: castulo.martinez@intel.com
|
||||
|
||||
load "../testlib"
|
||||
|
||||
test_setup() {
|
||||
|
||||
create_test_environment -r "$TEST_NAME" 10 1
|
||||
bump_format "$TEST_NAME"
|
||||
create_version -r "$TEST_NAME" 40 30 2
|
||||
|
||||
}
|
||||
|
||||
@test "CHK010: Check for available updates accross format bumps" {
|
||||
|
||||
# check-update should return the latest available version regardless
|
||||
# of if it is in a different format
|
||||
|
||||
run sudo sh -c "$SWUPD check-update $SWUPD_OPTS"
|
||||
|
||||
assert_status_is "$SWUPD_OK"
|
||||
expected_output=$(cat <<-EOM
|
||||
Current OS version: 10
|
||||
Latest server version: 40
|
||||
There is a new OS version available: 40
|
||||
EOM
|
||||
)
|
||||
assert_is_output "$expected_output"
|
||||
|
||||
}
|
||||
@@ -1356,6 +1356,7 @@ create_version() { # swupd_function
|
||||
sudo mkdir -p "$env_name"/web-dir/"$version"/{files,delta}
|
||||
sudo mkdir -p "$env_name"/web-dir/version/format"$format"
|
||||
write_to_protected_file "$env_name"/web-dir/version/format"$format"/latest "$version"
|
||||
write_to_protected_file "$env_name"/web-dir/version/latest_version "$version"
|
||||
if [ "$format" = staging ]; then
|
||||
format=1
|
||||
fi
|
||||
|
||||
@@ -5,7 +5,7 @@ load "../testlib"
|
||||
test_setup() {
|
||||
|
||||
create_test_environment -e "$TEST_NAME"
|
||||
set_latest_version "$TEST_NAME" 100
|
||||
create_version "$TEST_NAME" 100
|
||||
sudo rm -f "$TARGETDIR"/usr/lib/os-release
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ load "../testlib"
|
||||
global_setup() {
|
||||
|
||||
create_test_environment -e "$TEST_NAME"
|
||||
set_latest_version "$TEST_NAME" 100
|
||||
create_version "$TEST_NAME" 100
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user