Skip to content

Commit

Permalink
Merge pull request #69 from hnez/rauc-dbus-update
Browse files Browse the repository at this point in the history
rauc: use InstallBundle and InspectBundle instead of deprecated DBus methods
  • Loading branch information
hnez committed Jun 25, 2024
2 parents c75d701 + 38547a5 commit 0877d1b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
29 changes: 23 additions & 6 deletions src/dbus/rauc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ use installer::InstallerProxy;

#[cfg(feature = "demo_mode")]
mod imports {
use std::collections::HashMap;

pub(super) struct InstallerProxy<'a> {
_dummy: &'a (),
}
Expand All @@ -54,11 +56,24 @@ mod imports {
Some(Self { _dummy: &() })
}

pub async fn info(&self, _url: &str) -> anyhow::Result<(String, String)> {
let compatible = "LXA TAC".to_string();
let version = "4.0-0-20230428214619".to_string();

Ok((compatible, version))
pub async fn inspect_bundle(
&self,
_source: &str,
_args: HashMap<&str, zbus::zvariant::Value<'_>>,
) -> zbus::Result<HashMap<String, zbus::zvariant::OwnedValue>> {
let update: HashMap<String, String> = [
(
"compatible".into(),
"Linux Automation GmbH - LXA TAC".into(),
),
("version".into(), "24.04-20240415070800".into()),
]
.into();

let info: HashMap<String, zbus::zvariant::OwnedValue> =
[("update".into(), update.into())].into();

Ok(info)
}
}

Expand Down Expand Up @@ -532,7 +547,9 @@ impl Rauc {
// Poor-mans validation. It feels wrong to let someone point to any
// file on the TAC from the web interface.
if url.starts_with("http://") || url.starts_with("https://") {
if let Err(e) = proxy.install(&url).await {
let args = HashMap::new();

if let Err(e) = proxy.install_bundle(&url, args).await {
error!("Failed to install bundle: {}", e);
}
}
Expand Down
32 changes: 31 additions & 1 deletion src/dbus/rauc/update_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

use std::collections::HashMap;
use std::fs::{read_dir, read_to_string, DirEntry};
use std::os::unix::ffi::OsStrExt;
use std::path::Path;
Expand Down Expand Up @@ -62,6 +63,28 @@ pub struct ChannelFile {
pub polling_interval: Option<String>,
}

fn zvariant_walk_nested_dicts<'a>(map: &'a zvariant::Dict, path: &[&str]) -> Result<&'a str> {
let (&key, rem) = path
.split_first()
.ok_or_else(|| anyhow!("Got an empty path to walk"))?;

let value: &zvariant::Value = map
.get(key)?
.ok_or_else(|| anyhow!("Could not find key \"{key}\" in dict"))?;

if rem.is_empty() {
value.downcast_ref().ok_or_else(|| {
anyhow!("Failed to convert value in dictionary for key \"{key}\" to a string")
})
} else {
let value = value.downcast_ref().ok_or_else(|| {
anyhow!("Failed to convert value in dictionary for key \"{key}\" to a dict")
})?;

zvariant_walk_nested_dicts(value, rem)
}
}

impl Channel {
fn from_file(path: &Path) -> Result<Self> {
let file_name = || {
Expand Down Expand Up @@ -168,7 +191,14 @@ impl Channel {
self.bundle = None;

if self.enabled {
let (compatible, version) = proxy.info(&self.url).await?;
let args = HashMap::new();
let bundle = proxy.inspect_bundle(&self.url, args).await?;
let bundle: zvariant::Dict = bundle.into();

let compatible =
zvariant_walk_nested_dicts(&bundle, &["update", "compatible"])?.to_owned();
let version = zvariant_walk_nested_dicts(&bundle, &["update", "version"])?.to_owned();

self.bundle = Some(UpstreamBundle::new(compatible, version, slot_status));
}

Expand Down

0 comments on commit 0877d1b

Please sign in to comment.