Skip to content

Commit

Permalink
rauc: use InspectBundle instead of deprecated Info DBus API
Browse files Browse the repository at this point in the history
The InspectBundle method allows providing a dictionary of extra arguments,
which makes it more flexible than Info.
We do not need this flexibility yet, but at least we no longer use a
deprecated API.

Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
  • Loading branch information
hnez committed Jun 25, 2024
1 parent 9aa9d6e commit 960509e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
25 changes: 20 additions & 5 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 = "Linux Automation GmbH - LXA TAC".to_string();
let version = "24.04-20240415070800".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
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 960509e

Please sign in to comment.