diff --git a/crates/devolutions-agent-shared/src/update_json.rs b/crates/devolutions-agent-shared/src/update_json.rs index 9164d3dec..9a3444b96 100644 --- a/crates/devolutions-agent-shared/src/update_json.rs +++ b/crates/devolutions-agent-shared/src/update_json.rs @@ -57,9 +57,9 @@ mod tests { ("latest", VersionSpecification::Latest), ]; - for (serialized, deserizlized) in cases { + for (serialized, deserialized) in cases { let parsed = serde_json::from_str::(&format!("\"{}\"", serialized)).unwrap(); - assert_eq!(parsed, *deserizlized); + assert_eq!(parsed, *deserialized); let reserialized = serde_json::to_string(&parsed).unwrap(); assert_eq!(reserialized, format!("\"{}\"", serialized)); diff --git a/devolutions-agent/src/updater/io.rs b/devolutions-agent/src/updater/io.rs index 875627023..dcb189cb7 100644 --- a/devolutions-agent/src/updater/io.rs +++ b/devolutions-agent/src/updater/io.rs @@ -8,7 +8,7 @@ use tokio::{fs::File, io::AsyncWriteExt}; use crate::updater::UpdaterError; /// Download binary file to memory -pub async fn download_bytes(url: &str) -> Result, UpdaterError> { +pub async fn download_binary(url: &str) -> Result, UpdaterError> { info!(%url, "Downloading file from network..."); let body = reqwest::get(url) @@ -22,8 +22,8 @@ pub async fn download_bytes(url: &str) -> Result, UpdaterError> { } /// Download UTF-8 file to memory -pub async fn download_text(url: &str) -> Result { - let bytes = download_bytes(url).await?; +pub async fn download_utf8(url: &str) -> Result { + let bytes = download_binary(url).await?; String::from_utf8(bytes).map_err(|_| UpdaterError::Utf8) } @@ -50,11 +50,11 @@ pub async fn save_to_temp_file(data: &[u8], extension: Option<&str>) -> Result Result<(), UpdaterError> { - _impl_remove_file_on_reboot(file_path) + remove_file_on_reboot_impl(file_path) } #[cfg(windows)] -pub fn _impl_remove_file_on_reboot(file_path: &Utf8Path) -> Result<(), UpdaterError> { +pub fn remove_file_on_reboot_impl(file_path: &Utf8Path) -> Result<(), UpdaterError> { use windows::core::HSTRING; use windows::Win32::Storage::FileSystem::{MoveFileExW, MOVEFILE_DELAY_UNTIL_REBOOT}; @@ -70,7 +70,7 @@ pub fn _impl_remove_file_on_reboot(file_path: &Utf8Path) -> Result<(), UpdaterEr } #[cfg(not(windows))] -pub fn _impl_remove_file_on_reboot(_file_path: &Utf8Path) -> Result<(), UpdaterError> { - // NOTE: On UNIX-like platforms /tmp filder is used which is cleared by OS automatically. +pub fn impl_remove_file_on_reboot_impl(_file_path: &Utf8Path) -> Result<(), UpdaterError> { + // NOTE: On UNIX-like platforms /tmp folder is used which is cleared by OS automatically. Ok(()) } diff --git a/devolutions-agent/src/updater/mod.rs b/devolutions-agent/src/updater/mod.rs index d114e8231..b21b64560 100644 --- a/devolutions-agent/src/updater/mod.rs +++ b/devolutions-agent/src/updater/mod.rs @@ -24,7 +24,7 @@ use devolutions_gateway_task::{ShutdownSignal, Task}; use crate::config::ConfHandle; use integrity::validate_artifact_hash; -use io::{download_bytes, download_text, save_to_temp_file}; +use io::{download_binary, download_utf8, save_to_temp_file}; use package::{install_package, validate_package}; use productinfo::DEVOLUTIONS_PRODUCTINFO_URL; use security::set_file_dacl; @@ -83,12 +83,12 @@ impl Task for UpdaterTask { error!(%err, "Failed to watch update.json file"); } }) - .context("Failed to create file notify debouncer")?; + .context("failed to create file notify debouncer")?; notify_debouncer .watcher() .watch(update_file_path.as_std_path(), RecursiveMode::NonRecursive) - .context("Failed to start update file watcher")?; + .context("failed to start update file watcher")?; // Trigger initial check during task startup file_change_notification.notify_waiters(); @@ -149,9 +149,9 @@ async fn update_product(conf: ConfHandle, product: Product, order: UpdateOrder) let target_version = order.target_version; let hash = order.hash; - let package_data = download_bytes(&order.package_url) + let package_data = download_binary(&order.package_url) .await - .with_context(|| format!("Failed to download package file for `{product}`"))?; + .with_context(|| format!("failed to download package file for `{product}`"))?; let package_path = save_to_temp_file(&package_data, Some(product.get_package_extension())).await?; @@ -159,9 +159,9 @@ async fn update_product(conf: ConfHandle, product: Product, order: UpdateOrder) let ctx = UpdaterCtx { product, conf }; - validate_artifact_hash(&ctx, &package_data, &hash).context("Failed to validate package file integrity")?; + validate_artifact_hash(&ctx, &package_data, &hash).context("failed to validate package file integrity")?; - validate_package(&ctx, &package_path).context("Failed to validate package contents")?; + validate_package(&ctx, &package_path).context("failed to validate package contents")?; if ctx.conf.get_conf().debug.skip_msi_install { warn!(%product, "DEBUG MODE: Skipping package installation due to debug configuration"); @@ -180,9 +180,9 @@ async fn update_product(conf: ConfHandle, product: Product, order: UpdateOrder) async fn read_update_json(update_file_path: &Utf8Path) -> anyhow::Result { let update_json_data = tokio::fs::read(update_file_path) .await - .context("Failed to read update.json file")?; + .context("failed to read update.json file")?; let update_json: UpdateJson = - serde_json::from_slice(&update_json_data).context("Failed to parse update.json file")?; + serde_json::from_slice(&update_json_data).context("failed to parse update.json file")?; Ok(update_json) } @@ -221,15 +221,15 @@ async fn check_for_updates(product: Product, update_json: &UpdateJson) -> anyhow info!(%product, %target_version, "Ready to update the product"); - let product_info_db = download_text(DEVOLUTIONS_PRODUCTINFO_URL) + let product_info_db = download_utf8(DEVOLUTIONS_PRODUCTINFO_URL) .await - .context("Failed to download productinfo database")?; + .context("failed to download productinfo database")?; let product_info_db: productinfo::ProductInfoDb = product_info_db.parse()?; let product_info = product_info_db .get(product.get_productinfo_id()) - .ok_or_else(|| anyhow!("Product `{product}` info not found in remote database"))?; + .ok_or_else(|| anyhow!("product `{product}` info not found in remote database"))?; let remote_version = product_info.version.parse::()?; @@ -259,11 +259,11 @@ async fn init_update_json() -> anyhow::Result { let update_file_path = get_updater_file_path(); let default_update_json = - serde_json::to_string_pretty(&UpdateJson::default()).context("Failed to serialize default update.json")?; + serde_json::to_string_pretty(&UpdateJson::default()).context("failed to serialize default update.json")?; fs::write(&update_file_path, default_update_json) .await - .context("Failed to write default update.json file")?; + .context("failed to write default update.json file")?; // Set permissions for update.json file: match set_file_dacl(&update_file_path, security::UPDATE_JSON_DACL) { @@ -276,7 +276,7 @@ async fn init_update_json() -> anyhow::Result { .unwrap_or_else(|err| warn!(%err, "Failed to remove update.json file after failed permissions set")); // Treat as fatal error - return Err(anyhow!(err).context("Failed to set update.json file permissions")); + return Err(anyhow!(err).context("failed to set update.json file permissions")); } } diff --git a/devolutions-agent/src/updater/productinfo/db.rs b/devolutions-agent/src/updater/productinfo/db.rs index 7e71d1e3b..534f16966 100644 --- a/devolutions-agent/src/updater/productinfo/db.rs +++ b/devolutions-agent/src/updater/productinfo/db.rs @@ -61,7 +61,7 @@ mod tests { #[test] fn test_productinfo_parse() { - let input = include_str!("test_asset_db"); + let input = include_str!("../../../test_assets/test_asset_db"); let db: ProductInfoDb = input.parse().unwrap(); assert_eq!(db.get("Gatewaybin").unwrap().version, "2024.2.1.0"); diff --git a/devolutions-agent/src/updater/uuid.rs b/devolutions-agent/src/updater/uuid.rs index 332b56241..b56ed4a32 100644 --- a/devolutions-agent/src/updater/uuid.rs +++ b/devolutions-agent/src/updater/uuid.rs @@ -61,7 +61,7 @@ pub fn reversed_hex_to_uuid(mut hex: &str) -> Result { formatted.push('{'); - // Hypen pattern is not same as reversing pattern blocks + // Hyphen pattern is not same as reversing pattern blocks. const HYPEN_PATTERN: &[usize] = &[1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0]; for (pattern, hypen) in UUID_REVERSING_PATTERN.iter().zip(HYPEN_PATTERN) { diff --git a/devolutions-agent/src/updater/productinfo/test_asset_db b/devolutions-agent/test_assets/test_asset_db similarity index 100% rename from devolutions-agent/src/updater/productinfo/test_asset_db rename to devolutions-agent/test_assets/test_asset_db