Add trace logging to some vpkc methods

This commit is contained in:
Caelan Sayler
2024-12-21 09:43:44 +00:00
committed by Caelan
parent ee8ff2bbc4
commit 857fa9d30f
6 changed files with 128 additions and 2 deletions

70
Cargo.lock generated
View File

@@ -378,7 +378,7 @@ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
"clap_lex", "clap_lex",
"strsim", "strsim 0.11.1",
] ]
[[package]] [[package]]
@@ -479,6 +479,41 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
[[package]]
name = "darling"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim 0.9.3",
"syn 1.0.109",
]
[[package]]
name = "darling_macro"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72"
dependencies = [
"darling_core",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "deranged" name = "deranged"
version = "0.3.11" version = "0.3.11"
@@ -657,6 +692,12 @@ dependencies = [
"miniz_oxide", "miniz_oxide",
] ]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]] [[package]]
name = "form_urlencoded" name = "form_urlencoded"
version = "1.2.1" version = "1.2.1"
@@ -934,6 +975,12 @@ dependencies = [
"syn 2.0.90", "syn 2.0.90",
] ]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]] [[package]]
name = "idna" name = "idna"
version = "1.0.3" version = "1.0.3"
@@ -1090,6 +1137,18 @@ dependencies = [
"value-bag", "value-bag",
] ]
[[package]]
name = "log-derive"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a42526bb432bcd1b43571d5f163984effa25409a29f1a3242a54d0577d55bcf"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "log-panics" name = "log-panics"
version = "2.1.0" version = "2.1.0"
@@ -1691,6 +1750,12 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "strsim"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.11.1" version = "0.11.1"
@@ -2101,7 +2166,7 @@ dependencies = [
"sha1_smol", "sha1_smol",
"simple-stopwatch", "simple-stopwatch",
"simplelog", "simplelog",
"strsim", "strsim 0.11.1",
"strum", "strum",
"tempfile", "tempfile",
"time 0.3.37", "time 0.3.37",
@@ -2123,6 +2188,7 @@ dependencies = [
"lazy_static", "lazy_static",
"libc", "libc",
"log", "log",
"log-derive",
"serde_json", "serde_json",
"velopack", "velopack",
] ]

View File

@@ -25,6 +25,7 @@ rust-version = "1.75"
[workspace.dependencies] [workspace.dependencies]
velopack = { path = "src/lib-rust" } velopack = { path = "src/lib-rust" }
log = "0.4" log = "0.4"
log-derive = "0.4.1"
ureq = "2.10" ureq = "2.10"
url = "2.5" url = "2.5"
semver = "1.0" semver = "1.0"

View File

@@ -22,6 +22,7 @@ velopack.workspace = true
anyhow.workspace = true anyhow.workspace = true
lazy_static.workspace = true lazy_static.workspace = true
log.workspace = true log.workspace = true
log-derive.workspace = true
libc.workspace = true libc.workspace = true
serde_json.workspace = true serde_json.workspace = true

View File

@@ -353,6 +353,8 @@ typedef std::function<void(size_t)> vpkc_progress_send_t;
* Abstract class for retrieving release feeds and downloading assets. You should subclass this and * Abstract class for retrieving release feeds and downloading assets. You should subclass this and
* implement/override the GetReleaseFeed and DownloadReleaseEntry methods. * implement/override the GetReleaseFeed and DownloadReleaseEntry methods.
* This class is used by the UpdateManager to fetch release feeds and download assets in a custom way. * This class is used by the UpdateManager to fetch release feeds and download assets in a custom way.
* SAFETY: It is your responsibility to ensure that a derived class instance is thread-safe,
* as Velopack may call methods on this class from multiple threads.
*/ */
class IUpdateSource { class IUpdateSource {
friend class UpdateManager; friend class UpdateManager;
@@ -386,7 +388,15 @@ public:
}, },
this); this);
} }
/**
* Fetches the release feed json for the specified releases name, and returns it as a string.
*/
virtual const std::string GetReleaseFeed(const std::string releasesName) = 0; virtual const std::string GetReleaseFeed(const std::string releasesName) = 0;
/**
* Downloads an asset to the specified local file path. Progress is reported back to Velopack via a callback.
*/
virtual bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) = 0; virtual bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) = 0;
}; };
@@ -396,6 +406,12 @@ public:
class FileSource : public IUpdateSource { class FileSource : public IUpdateSource {
public: public:
FileSource(const std::string& filePath) : IUpdateSource(vpkc_new_source_file(filePath.c_str())) { } FileSource(const std::string& filePath) : IUpdateSource(vpkc_new_source_file(filePath.c_str())) { }
const std::string GetReleaseFeed(const std::string releasesName) override {
throw std::runtime_error("Not implemented");
}
bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) override {
throw std::runtime_error("Not implemented");
}
}; };
/** /**
@@ -404,6 +420,12 @@ public:
class HttpSource : public IUpdateSource { class HttpSource : public IUpdateSource {
public: public:
HttpSource(const std::string& httpUrl) : IUpdateSource(vpkc_new_source_http_url(httpUrl.c_str())) { } HttpSource(const std::string& httpUrl) : IUpdateSource(vpkc_new_source_http_url(httpUrl.c_str())) { }
const std::string GetReleaseFeed(const std::string releasesName) override {
throw std::runtime_error("Not implemented");
}
bool DownloadReleaseEntry(const VelopackAsset& asset, const std::string localFilePath, vpkc_progress_send_t progress) override {
throw std::runtime_error("Not implemented");
}
}; };
/** /**

View File

@@ -13,11 +13,14 @@ use raw::*;
use anyhow::{anyhow, bail}; use anyhow::{anyhow, bail};
use libc::{c_char, c_void, size_t}; use libc::{c_char, c_void, size_t};
use log_derive::{logfn, logfn_inputs};
use std::{ffi::CString, ptr}; use std::{ffi::CString, ptr};
use velopack::{sources, Error as VelopackError, UpdateCheck, UpdateManager, VelopackApp}; use velopack::{sources, Error as VelopackError, UpdateCheck, UpdateManager, VelopackApp};
/// Create a new FileSource update source for a given file path. /// Create a new FileSource update source for a given file path.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_new_source_file(psz_file_path: *const c_char) -> *mut vpkc_update_source_t { pub extern "C" fn vpkc_new_source_file(psz_file_path: *const c_char) -> *mut vpkc_update_source_t {
if let Some(update_path) = c_to_string_opt(psz_file_path) { if let Some(update_path) = c_to_string_opt(psz_file_path) {
UpdateSourceRawPtr::new(Box::new(sources::FileSource::new(update_path))) UpdateSourceRawPtr::new(Box::new(sources::FileSource::new(update_path)))
@@ -28,6 +31,8 @@ pub extern "C" fn vpkc_new_source_file(psz_file_path: *const c_char) -> *mut vpk
/// Create a new HttpSource update source for a given HTTP URL. /// Create a new HttpSource update source for a given HTTP URL.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_new_source_http_url(psz_http_url: *const c_char) -> *mut vpkc_update_source_t { pub extern "C" fn vpkc_new_source_http_url(psz_http_url: *const c_char) -> *mut vpkc_update_source_t {
if let Some(update_url) = c_to_string_opt(psz_http_url) { if let Some(update_url) = c_to_string_opt(psz_http_url) {
UpdateSourceRawPtr::new(Box::new(sources::FileSource::new(update_url))) UpdateSourceRawPtr::new(Box::new(sources::FileSource::new(update_url)))
@@ -42,6 +47,8 @@ pub extern "C" fn vpkc_new_source_http_url(psz_http_url: *const c_char) -> *mut
/// but note that if the source is still in use by an UpdateManager, it will not be freed until the UpdateManager is freed. /// but note that if the source is still in use by an UpdateManager, it will not be freed until the UpdateManager is freed.
/// Therefore to avoid possible issues, it is recommended to create this type of source once for the lifetime of your application. /// Therefore to avoid possible issues, it is recommended to create this type of source once for the lifetime of your application.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_new_source_custom_callback( pub extern "C" fn vpkc_new_source_custom_callback(
cb_release_feed: vpkc_release_feed_delegate_t, cb_release_feed: vpkc_release_feed_delegate_t,
cb_free_release_feed: vpkc_free_release_feed_t, cb_free_release_feed: vpkc_free_release_feed_t,
@@ -71,6 +78,8 @@ pub extern "C" fn vpkc_source_report_progress(progress_callback_id: size_t, prog
/// Frees a vpkc_update_source_t instance. /// Frees a vpkc_update_source_t instance.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_free_source(p_source: *mut vpkc_update_source_t) { pub extern "C" fn vpkc_free_source(p_source: *mut vpkc_update_source_t) {
UpdateSourceRawPtr::free(p_source); UpdateSourceRawPtr::free(p_source);
} }
@@ -80,6 +89,8 @@ pub extern "C" fn vpkc_free_source(p_source: *mut vpkc_update_source_t) {
/// @param options Optional extra configuration for update manager. /// @param options Optional extra configuration for update manager.
/// @param locator Override the default locator configuration (usually used for testing / mocks). /// @param locator Override the default locator configuration (usually used for testing / mocks).
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_new_update_manager( pub extern "C" fn vpkc_new_update_manager(
psz_url_or_path: *const c_char, psz_url_or_path: *const c_char,
p_options: *mut vpkc_update_options_t, p_options: *mut vpkc_update_options_t,
@@ -102,6 +113,8 @@ pub extern "C" fn vpkc_new_update_manager(
/// @param options Optional extra configuration for update manager. /// @param options Optional extra configuration for update manager.
/// @param locator Override the default locator configuration (usually used for testing / mocks). /// @param locator Override the default locator configuration (usually used for testing / mocks).
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_new_update_manager_with_source( pub extern "C" fn vpkc_new_update_manager_with_source(
p_source: *mut vpkc_update_source_t, p_source: *mut vpkc_update_source_t,
p_options: *mut vpkc_update_options_t, p_options: *mut vpkc_update_options_t,
@@ -120,6 +133,8 @@ pub extern "C" fn vpkc_new_update_manager_with_source(
/// Returns the currently installed version of the app. /// Returns the currently installed version of the app.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_get_current_version(p_manager: *mut vpkc_update_manager_t, psz_version: *mut c_char, c_version: size_t) -> size_t { pub extern "C" fn vpkc_get_current_version(p_manager: *mut vpkc_update_manager_t, psz_version: *mut c_char, c_version: size_t) -> size_t {
match p_manager.to_opaque_ref() { match p_manager.to_opaque_ref() {
Some(manager) => { Some(manager) => {
@@ -132,6 +147,8 @@ pub extern "C" fn vpkc_get_current_version(p_manager: *mut vpkc_update_manager_t
/// Returns the currently installed app id. /// Returns the currently installed app id.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_get_app_id(p_manager: *mut vpkc_update_manager_t, psz_id: *mut c_char, c_id: size_t) -> size_t { pub extern "C" fn vpkc_get_app_id(p_manager: *mut vpkc_update_manager_t, psz_id: *mut c_char, c_id: size_t) -> size_t {
match p_manager.to_opaque_ref() { match p_manager.to_opaque_ref() {
Some(manager) => { Some(manager) => {
@@ -145,6 +162,8 @@ pub extern "C" fn vpkc_get_app_id(p_manager: *mut vpkc_update_manager_t, psz_id:
/// Returns whether the app is in portable mode. On Windows this can be true or false. /// Returns whether the app is in portable mode. On Windows this can be true or false.
/// On MacOS and Linux this will always be true. /// On MacOS and Linux this will always be true.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_is_portable(p_manager: *mut vpkc_update_manager_t) -> bool { pub extern "C" fn vpkc_is_portable(p_manager: *mut vpkc_update_manager_t) -> bool {
match p_manager.to_opaque_ref() { match p_manager.to_opaque_ref() {
Some(manager) => manager.get_is_portable(), Some(manager) => manager.get_is_portable(),
@@ -155,6 +174,8 @@ pub extern "C" fn vpkc_is_portable(p_manager: *mut vpkc_update_manager_t) -> boo
/// Returns an UpdateInfo object if there is an update downloaded which still needs to be applied. /// Returns an UpdateInfo object if there is an update downloaded which still needs to be applied.
/// You can pass the UpdateInfo object to waitExitThenApplyUpdate to apply the update. /// You can pass the UpdateInfo object to waitExitThenApplyUpdate to apply the update.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_update_pending_restart(p_manager: *mut vpkc_update_manager_t, p_asset: *mut vpkc_asset_t) -> bool { pub extern "C" fn vpkc_update_pending_restart(p_manager: *mut vpkc_update_manager_t, p_asset: *mut vpkc_asset_t) -> bool {
match p_manager.to_opaque_ref() { match p_manager.to_opaque_ref() {
Some(manager) => match manager.get_update_pending_restart() { Some(manager) => match manager.get_update_pending_restart() {
@@ -171,6 +192,8 @@ pub extern "C" fn vpkc_update_pending_restart(p_manager: *mut vpkc_update_manage
/// Checks for updates, returning None if there are none available. If there are updates available, this method will return an /// Checks for updates, returning None if there are none available. If there are updates available, this method will return an
/// UpdateInfo object containing the latest available release, and any delta updates that can be applied if they are available. /// UpdateInfo object containing the latest available release, and any delta updates that can be applied if they are available.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_check_for_updates(p_manager: *mut vpkc_update_manager_t, p_update: *mut vpkc_update_info_t) -> vpkc_update_check_t { pub extern "C" fn vpkc_check_for_updates(p_manager: *mut vpkc_update_manager_t, p_update: *mut vpkc_update_info_t) -> vpkc_update_check_t {
match p_manager.to_opaque_ref() { match p_manager.to_opaque_ref() {
Some(manager) => match manager.check_for_updates() { Some(manager) => match manager.check_for_updates() {
@@ -201,6 +224,8 @@ pub extern "C" fn vpkc_check_for_updates(p_manager: *mut vpkc_update_manager_t,
/// - If there is no delta update available, or there is an error preparing delta /// - If there is no delta update available, or there is an error preparing delta
/// packages, this method will fall back to downloading the full version of the update. /// packages, this method will fall back to downloading the full version of the update.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_download_updates( pub extern "C" fn vpkc_download_updates(
p_manager: *mut vpkc_update_manager_t, p_manager: *mut vpkc_update_manager_t,
p_update: *mut vpkc_update_info_t, p_update: *mut vpkc_update_info_t,
@@ -265,6 +290,8 @@ pub extern "C" fn vpkc_download_updates(
/// You should then clean up any state and exit your app. The updater will apply updates and then /// You should then clean up any state and exit your app. The updater will apply updates and then
/// optionally restart your app. The updater will only wait for 60 seconds before giving up. /// optionally restart your app. The updater will only wait for 60 seconds before giving up.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_wait_exit_then_apply_update( pub extern "C" fn vpkc_wait_exit_then_apply_update(
p_manager: *mut vpkc_update_manager_t, p_manager: *mut vpkc_update_manager_t,
p_asset: *mut vpkc_asset_t, p_asset: *mut vpkc_asset_t,
@@ -288,18 +315,24 @@ pub extern "C" fn vpkc_wait_exit_then_apply_update(
/// Frees a vpkc_update_manager_t instance. /// Frees a vpkc_update_manager_t instance.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_free_update_manager(p_manager: *mut vpkc_update_manager_t) { pub extern "C" fn vpkc_free_update_manager(p_manager: *mut vpkc_update_manager_t) {
UpdateManagerRawPtr::free(p_manager); UpdateManagerRawPtr::free(p_manager);
} }
/// Frees a vpkc_update_info_t instance. /// Frees a vpkc_update_info_t instance.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_free_update_info(p_update_info: *mut vpkc_update_info_t) { pub extern "C" fn vpkc_free_update_info(p_update_info: *mut vpkc_update_info_t) {
unsafe { free_updateinfo(p_update_info) }; unsafe { free_updateinfo(p_update_info) };
} }
/// Frees a vpkc_asset_t instance. /// Frees a vpkc_asset_t instance.
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_free_asset(p_asset: *mut vpkc_asset_t) { pub extern "C" fn vpkc_free_asset(p_asset: *mut vpkc_asset_t) {
unsafe { free_velopackasset(p_asset) }; unsafe { free_velopackasset(p_asset) };
} }
@@ -308,6 +341,8 @@ pub extern "C" fn vpkc_free_asset(p_asset: *mut vpkc_asset_t) {
/// This should be used as early as possible in your application startup code. /// This should be used as early as possible in your application startup code.
/// (eg. the beginning of main() or wherever your entry point is) /// (eg. the beginning of main() or wherever your entry point is)
#[no_mangle] #[no_mangle]
#[logfn(Trace)]
#[logfn_inputs(Trace)]
pub extern "C" fn vpkc_app_run(p_user_data: *mut c_void) { pub extern "C" fn vpkc_app_run(p_user_data: *mut c_void) {
let app_options = VELOPACK_APP.read().unwrap(); let app_options = VELOPACK_APP.read().unwrap();
let mut app = VelopackApp::build(); let mut app = VelopackApp::build();

View File

@@ -5,6 +5,7 @@ use velopack::{locator::VelopackLocatorConfig, UpdateInfo, UpdateOptions, Velopa
/// The result of a call to check for updates. This can indicate that an update is available, or that an error occurred. /// The result of a call to check for updates. This can indicate that an update is available, or that an error occurred.
#[repr(i8)] #[repr(i8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum vpkc_update_check_t { pub enum vpkc_update_check_t {
UPDATE_ERROR = -1, UPDATE_ERROR = -1,
UPDATE_AVAILABLE = 0, UPDATE_AVAILABLE = 0,