chore: use a number instead of a string for next boot patch number (#34)

This commit is contained in:
Bryan Oltman
2023-06-19 22:49:59 -04:00
committed by GitHub
parent ea48f6cb4f
commit 0222f526a6
2 changed files with 16 additions and 17 deletions
+5 -4
View File
@@ -56,13 +56,14 @@ bool shorebird_init(const struct AppParameters *c_params,
const char *c_yaml);
/**
* Return the active patch number, or NULL if there is no active patch.
* The patch number that will boot on the next run of the app, or 0 if there is
* no next patch.
*/
SHOREBIRD_EXPORT char *shorebird_next_boot_patch_number(void);
SHOREBIRD_EXPORT uintptr_t shorebird_next_boot_patch_number(void);
/**
* Return the path to the active patch for the app, or NULL if there is no
* active patch.
* The path to the patch that will boot on the next run of the app, or NULL if
* there is no next patch.
*/
SHOREBIRD_EXPORT char *shorebird_next_boot_patch_path(void);
+11 -13
View File
@@ -116,21 +116,19 @@ pub extern "C" fn shorebird_init(
)
}
/// Return the active patch number, or NULL if there is no active patch.
/// The patch number that will boot on the next run of the app, or 0 if there is
/// no next patch.
#[no_mangle]
pub extern "C" fn shorebird_next_boot_patch_number() -> *mut c_char {
pub extern "C" fn shorebird_next_boot_patch_number() -> usize {
log_on_error(
|| {
let maybe_patch_number = updater::next_boot_patch()?.map(|p| p.number.to_string());
to_c_string(maybe_patch_number)
},
|| Ok(updater::next_boot_patch()?.map(|p| p.number).unwrap_or(0)),
"fetching next_boot_patch_number",
std::ptr::null_mut(),
0,
)
}
/// Return the path to the active patch for the app, or NULL if there is no
/// active patch.
/// The path to the patch that will boot on the next run of the app, or NULL if
/// there is no next patch.
#[no_mangle]
pub extern "C" fn shorebird_next_boot_patch_path() -> *mut c_char {
log_on_error(
@@ -323,9 +321,9 @@ mod test {
free_c_string(c_yaml);
free_parameters(c_params);
// Number and path are empty (but do not crash) when we have an
// Number is 0 and path is empty (but do not crash) when we have an
// empty cache and update has not been called.
assert_eq!(shorebird_next_boot_patch_number(), null_mut());
assert_eq!(shorebird_next_boot_patch_number(), 0);
assert_eq!(shorebird_next_boot_patch_path(), null_mut());
// Similarly we can report launches with no patch without crashing.
@@ -389,8 +387,8 @@ mod test {
);
shorebird_update();
let version = to_rust(shorebird_next_boot_patch_number()).unwrap();
assert!(version.eq("1"));
let version = shorebird_next_boot_patch_number();
assert_eq!(version, 1);
// Read path contents into memory and check against expected.
let path = to_rust(shorebird_next_boot_patch_path()).unwrap();