Refactor sysmerge(8) and sysupgrade(8) ABI and version comparisons.

This commit is contained in:
Jonas 'Sortie' Termansen 2017-04-10 16:37:30 +02:00
parent b0496023a1
commit 4c2ef980b1
5 changed files with 59 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016 Jonas 'Sortie' Termansen. * Copyright (c) 2016, 2017 Jonas 'Sortie' Termansen.
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -51,12 +51,8 @@ void upgrade_finalize(const struct release* old_release,
(void) target_prefix; (void) target_prefix;
// TODO: After releasing Sortix 1.1, remove this compatibility. // TODO: After releasing Sortix 1.1, remove this compatibility.
if ( old_release->version_major < 1 || if ( version_compare(old_release->version_major, old_release->version_minor,
(old_release->version_major == 1 && old_release->version_dev, 1, 1, false) < 0 ) // < 1.1
old_release->version_minor < 1) ||
(old_release->version_major == 1 &&
old_release->version_minor == 1 &&
old_release->version_dev) )
{ {
char* random_seed_path; char* random_seed_path;
if ( asprintf(&random_seed_path, "%sboot/random.seed", target_prefix) < 0 ) if ( asprintf(&random_seed_path, "%sboot/random.seed", target_prefix) < 0 )

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016 Jonas 'Sortie' Termansen. * Copyright (c) 2015, 2016, 2017 Jonas 'Sortie' Termansen.
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -27,6 +27,44 @@
#include "release.h" #include "release.h"
int abi_compare(unsigned long a_major, unsigned long a_minor,
unsigned long b_major, unsigned long b_minor)
{
if ( a_major < b_major )
return -1;
if ( a_major > b_major )
return 1;
if ( a_minor < b_minor )
return -1;
if ( a_minor > b_minor )
return 1;
return 0;
}
bool abi_compatible(unsigned long a_major, unsigned long a_minor,
unsigned long b_major, unsigned long b_minor)
{
return a_major == b_major && a_minor <= b_minor;
}
int version_compare(unsigned long a_major, unsigned long a_minor, bool a_dev,
unsigned long b_major, unsigned long b_minor, bool b_dev)
{
if ( a_major < b_major )
return -1;
if ( a_major > b_minor )
return 1;
if ( a_minor < b_minor )
return -1;
if ( a_minor > b_minor )
return 1;
if ( a_dev && !b_dev )
return -1;
if ( !a_dev && b_dev )
return 1;
return 0;
}
void release_free(struct release* release) void release_free(struct release* release)
{ {
free(release->pretty_name); free(release->pretty_name);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016 Jonas 'Sortie' Termansen. * Copyright (c) 2015, 2016, 2017 Jonas 'Sortie' Termansen.
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -30,7 +30,15 @@ struct release
unsigned long abi_minor; unsigned long abi_minor;
}; };
int abi_compare(unsigned long a_major, unsigned long a_minor,
unsigned long b_major, unsigned long b_minor);
bool abi_compatible(unsigned long a_major, unsigned long a_minor,
unsigned long b_major, unsigned long b_minor);
int version_compare(unsigned long a_major, unsigned long a_minor, bool a_dev,
unsigned long b_major, unsigned long b_minor, bool b_dev);
void release_free(struct release* release); void release_free(struct release* release);
int release_compare_abi(const struct release* a, const struct release* b);
int release_compare_version(const struct release* a, const struct release* b);
bool os_release_load(struct release* release, bool os_release_load(struct release* release,
const char* path, const char* path,
const char* errpath); const char* errpath);

View File

@ -213,8 +213,9 @@ int main(int argc, char* argv[])
struct conf conf; struct conf conf;
load_upgrade_conf(&conf, "/etc/upgrade.conf"); load_upgrade_conf(&conf, "/etc/upgrade.conf");
bool can_run_new_abi = new_release.abi_major == old_release.abi_major && bool can_run_new_abi =
new_release.abi_minor <= old_release.abi_minor; abi_compatible(new_release.abi_major, new_release.abi_minor,
old_release.abi_major, old_release.abi_minor);
bool header; bool header;
bool copy_files; bool copy_files;

View File

@ -626,9 +626,8 @@ int main(void)
text("\n"); text("\n");
} }
if ( new_release.abi_major < target_release->abi_major || if ( abi_compare(new_release.abi_major, new_release.abi_minor,
(target_release->abi_major == new_release.abi_major && target_release->abi_major, target_release->abi_minor) < 0 )
new_release.abi_minor < target_release->abi_minor) )
{ {
text("Warning: You are downgrading an existing installation to an " text("Warning: You are downgrading an existing installation to an "
"release with an earlier ABI. This is not supported and there is " "release with an earlier ABI. This is not supported and there is "
@ -646,8 +645,9 @@ int main(void)
text("\n"); text("\n");
} }
bool can_run_old_abi = target_release->abi_major == new_release.abi_major && bool can_run_old_abi =
target_release->abi_minor <= new_release.abi_minor; abi_compatible(target_release->abi_major, target_release->abi_minor,
new_release.abi_major, new_release.abi_minor);
mountpoints = target->mountpoints; mountpoints = target->mountpoints;
mountpoints_used = target->mountpoints_used; mountpoints_used = target->mountpoints_used;