Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions devolutions-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ features = [

[target.'cfg(windows)'.build-dependencies]
embed-resource = "3.0"

[target.'cfg(windows)'.dev-dependencies]
expect-test = "1.5"
14 changes: 10 additions & 4 deletions devolutions-agent/src/updater/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ pub(crate) enum UpdaterError {
AclString { acl: String },
#[error("failed to set permissions for file: `{file_path}`")]
SetFilePermissions { file_path: Utf8PathBuf },
#[error("invalid productinfo.json format")]
ProductInfo,
#[error(
"could not find required file in productinfo.json for product `{product}` (arch: {arch}, type: {file_type})"
)]
ProductFileNotFound {
product: String,
arch: String,
file_type: String,
},
#[error(transparent)]
WindowsRegistry(#[from] devolutions_agent_shared::windows::registry::RegistryError),
#[error("missing registry value")]
MissingRegistryValue,
#[error("failed to download update")]
FileDownload { source: reqwest::Error, file_path: String },
#[error("failed to download file at {url}")]
FileDownload { source: reqwest::Error, url: String },
#[error("invalid UTF-8")]
Utf8,
#[error("IO error")]
Expand Down
4 changes: 2 additions & 2 deletions devolutions-agent/src/updater/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use tokio::io::AsyncWriteExt;

use crate::updater::UpdaterError;

/// Download binary file to memory
/// Download binary file to memory.
pub(crate) async fn download_binary(url: &str) -> Result<Vec<u8>, UpdaterError> {
info!(%url, "Downloading file from network...");

let body = reqwest::get(url)
.and_then(|response| response.bytes())
.map_err(|source| UpdaterError::FileDownload {
source,
file_path: url.to_owned(),
url: url.to_owned(),
})
.await?;
Ok(body.to_vec())
Expand Down
28 changes: 22 additions & 6 deletions devolutions-agent/src/updater/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use self::product_actions::{ProductUpdateActions, build_product_actions};
use self::productinfo::DEVOLUTIONS_PRODUCTINFO_URL;
use self::security::set_file_dacl;
use crate::config::ConfHandle;
use crate::updater::productinfo::ProductInfoDb;

pub(crate) use self::error::UpdaterError;
pub(crate) use self::product::Product;
Expand Down Expand Up @@ -257,15 +258,30 @@ 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_utf8(DEVOLUTIONS_PRODUCTINFO_URL)
let product_info_json = download_utf8(DEVOLUTIONS_PRODUCTINFO_URL)
.await
.context("failed to download productinfo database")?;

let product_info_db: productinfo::ProductInfoDb = product_info_db.parse()?;
let parse_result = ProductInfoDb::parse_product_info(&product_info_json);

let product_info = product_info_db
.get(product.get_productinfo_id())
.ok_or_else(|| anyhow!("product `{product}` info not found in remote database"))?;
let product_info = parse_result
.db
.lookup_current_msi_for_target_arch(product.get_productinfo_id())
.ok_or_else(|| {
// At this point, log all parsing errors as warnings so we can investigate.
for e in parse_result.errors {
warn!(
error = format!("{:#}", anyhow::Error::new(e)),
"productinfo.json parsing error"
);
}

UpdaterError::ProductFileNotFound {
product: product.get_productinfo_id().to_owned(),
arch: productinfo::get_target_arch().to_owned(),
file_type: "msi".to_owned(),
}
})?;

let remote_version = product_info.version.parse::<DateVersion>()?;

Expand All @@ -280,7 +296,7 @@ async fn check_for_updates(product: Product, update_json: &UpdateJson) -> anyhow
target_version: remote_version,
downgrade: None,
package_url: product_info.url.clone(),
hash: product_info.hash.clone(),
hash: Some(product_info.hash.clone()),
}))
}
VersionSpecification::Specific(version) => {
Expand Down
Loading