Skip to content

Commit

Permalink
Merge pull request #344 from rgallor/fix/purge-property-0.6
Browse files Browse the repository at this point in the history
chore(forward): forward port release v0.5.4
  • Loading branch information
harlem88 authored May 24, 2024
2 parents 7c7dc88 + 323362a commit e4cd28a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.4] - 2024-05-22
### Fixed
- Purge property deletes only the server property [#342](https://github.com/astarte-platform/astarte-device-sdk-rust/pull/342)

## [0.6.5] - 2024-04-08
### Fixed
- Delete all interface's properties, using the correct mapping, when an
Expand Down
2 changes: 2 additions & 0 deletions astarte-device-sdk-derive/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.4] - 2024-05-22

## [0.6.5] - 2024-04-08

## [0.6.4] - 2024-03-20
Expand Down
19 changes: 15 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ where
if interface == "control" && path == "/consumer/properties" {
debug!("Purging properties");

self.purge_properties(&payload).await?;
self.purge_server_properties(&payload).await?;

continue;
}
Expand Down Expand Up @@ -496,12 +496,23 @@ where
format!("{}/{}", self.realm, self.device_id)
}

async fn purge_properties(&self, bdata: &[u8]) -> Result<(), Error> {
/// This function deletes all the stored server owned properties after receiving a publish on
/// `/control/consumer/properties`
async fn purge_server_properties(&self, bdata: &[u8]) -> Result<(), Error> {
let paths = properties::extract_set_properties(bdata)?;

let interfaces = self.interfaces.read().await;

let stored_props = self.store.load_all_props().await?;

let paths = properties::extract_set_properties(bdata)?;
let server_owned_properties = stored_props.into_iter().filter(|prop| {
interfaces
.get_property(&prop.interface)
.map(|i| i.ownership())
== Some(Ownership::Server)
});

for stored_prop in stored_props {
for stored_prop in server_owned_properties {
if paths.contains(&format!("{}{}", stored_prop.interface, stored_prop.path)) {
continue;
}
Expand Down

0 comments on commit e4cd28a

Please sign in to comment.