Skip to content

Commit bd7b04d

Browse files
committed
save
Signed-off-by: Jan Zachmann <50990105+JanZachmann@users.noreply.github.com>
1 parent c828158 commit bd7b04d

File tree

13 files changed

+252
-385
lines changed

13 files changed

+252
-385
lines changed

Cargo.lock

Lines changed: 4 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
88
name = "omnect-device-service"
99
readme = "README.md"
1010
repository = "https://github.com/omnect/omnect-device-service.git"
11-
version = "0.41.6"
11+
version = "0.41.9"
1212

1313
[dependencies]
1414
actix-server = { version = "2.6", default-features = false }
@@ -25,12 +25,11 @@ freedesktop_entry_parser = { version = "1.3", default-features = false }
2525
futures = { version = "0.3", default-features = false }
2626
futures-util = { version = "0.3", default-features = false }
2727
glob = { version = "0.3", default-features = false }
28+
inotify = { version = "0.11", default-features = false, features = ["stream"] }
2829
lazy_static = { version = "1.5", default-features = false }
2930
log = { version = "0.4", default-features = false }
3031
log-panics = { version = "2", default-features = false }
3132
modemmanager = { git = "https://github.com/omnect/modemmanager.git", tag = "0.3.4", default-features = false, optional = true }
32-
notify = { version = "8.0", default-features = false }
33-
notify-debouncer-full = { version = "0.5", default-features = false }
3433
regex-lite = { version = "0.1", default-features = true }
3534
reqwest = { version = "0.12", default-features = false, features = [
3635
"default-tls",
@@ -64,7 +63,6 @@ tokio-stream = { version = "0.1", default-features = false, features = [
6463
"time",
6564
] }
6665
toml = { version = "0.8", default-features = false, features = ["parse"] }
67-
typeid = { version = "1.0", default-features = false }
6866
uuid = { version = "1.17", default-features = false }
6967
x509-parser = { version = "0.17", default-features = false }
7068
zbus = { version = "5.7", default-features = false, features = ["tokio"] }

src/twin/consent.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
use crate::{
22
common::{from_json_file, to_json_file},
3-
twin::{Feature, feature::*},
3+
twin::feature::{self, *},
44
};
55
use anyhow::{Context, Result, bail, ensure};
66
use azure_iot_sdk::client::IotMessage;
7+
use inotify::WatchMask;
78
use log::{info, warn};
8-
use notify_debouncer_full::notify::*;
99
use serde::{Deserialize, Serialize};
1010
use serde_json::json;
11-
use std::{collections::HashMap, env, path::Path};
11+
use std::{
12+
collections::HashMap,
13+
env,
14+
path::{Path, PathBuf},
15+
};
1216
use tokio::sync::mpsc::Sender;
1317

1418
macro_rules! consent_path {
@@ -54,6 +58,7 @@ pub struct ConsentConfig {
5458
}
5559

5660
pub struct DeviceUpdateConsent {
61+
file_map: HashMap<std::ffi::c_int, PathBuf>,
5762
tx_reported_properties: Option<Sender<serde_json::Value>>,
5863
}
5964

@@ -87,8 +92,13 @@ impl Feature for DeviceUpdateConsent {
8792

8893
async fn command(&mut self, cmd: &Command) -> CommandResult {
8994
match cmd {
90-
Command::WatchPath(file) => {
91-
self.report_consent(from_json_file(&file.path)?).await?;
95+
Command::WatchPath(cmd) => {
96+
self.report_consent(from_json_file(
97+
self.file_map
98+
.get(&cmd.event.wd.get_watch_descriptor_id())
99+
.context("context")?,
100+
)?)
101+
.await?;
92102
}
93103
Command::DesiredGeneralConsent(cmd) => {
94104
self.update_general_consent(cmd).await?;
@@ -108,22 +118,18 @@ impl DeviceUpdateConsent {
108118
const ID: &'static str = "device_update_consent";
109119

110120
pub fn new() -> Result<Self> {
121+
let mut file_map = HashMap::new();
122+
111123
for path in [request_consent_path!(), history_consent_path!()] {
112-
watch_path(
113-
Watch {
114-
command: PathCommand {
115-
feature_id: typeid::ConstTypeId::of::<Self>(),
116-
path,
117-
},
118-
event_kinds: vec![EventKind::Modify(event::ModifyKind::Data(
119-
event::DataChange::Content,
120-
))],
121-
},
122-
RecursiveMode::Recursive,
123-
)?;
124+
file_map.insert(
125+
feature::add_watch::<Self>(&path, WatchMask::MODIFY)?.get_watch_descriptor_id(),
126+
path,
127+
);
124128
}
129+
125130
Ok(DeviceUpdateConsent {
126131
tx_reported_properties: None,
132+
file_map,
127133
})
128134
}
129135

src/twin/factory_reset.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use crate::{
22
bootloader_env,
33
common::from_json_file,
44
systemd,
5-
twin::{Feature, feature::*},
5+
twin::feature::{self, *},
66
web_service,
77
};
88
use anyhow::{Context, Result, bail};
99
use azure_iot_sdk::client::IotMessage;
10+
use inotify::WatchMask;
1011
use log::{debug, info, warn};
11-
use notify_debouncer_full::notify::*;
1212
use serde::{Deserialize, Serialize};
1313
use serde_json::{from_reader, json};
1414
use serde_repr::*;
@@ -17,7 +17,7 @@ use std::{
1717
env,
1818
fs::{File, read_dir},
1919
io::BufReader,
20-
path::PathBuf,
20+
path::Path,
2121
};
2222
use tokio::sync::mpsc::Sender;
2323

@@ -37,8 +37,8 @@ macro_rules! config_path {
3737

3838
macro_rules! custom_config_dir_path {
3939
() => {
40-
PathBuf::from(
41-
env::var("FACTORY_RESET_CUSTOM_CONFIG_DIR_PATH")
40+
Path::new(
41+
&env::var("FACTORY_RESET_CUSTOM_CONFIG_DIR_PATH")
4242
.unwrap_or("/etc/omnect/factory-reset.d".to_string()),
4343
)
4444
};
@@ -186,18 +186,9 @@ impl FactoryReset {
186186
result: FactoryReset::factory_reset_result()?,
187187
};
188188

189-
watch_path(
190-
Watch {
191-
command: PathCommand {
192-
feature_id: typeid::ConstTypeId::of::<Self>(),
193-
path: custom_config_dir_path!(),
194-
},
195-
event_kinds: vec![
196-
EventKind::Create(event::CreateKind::File),
197-
EventKind::Remove(event::RemoveKind::File),
198-
],
199-
},
200-
RecursiveMode::Recursive,
189+
feature::add_watch::<Self>(
190+
custom_config_dir_path!(),
191+
WatchMask::CREATE | WatchMask::DELETE,
201192
)?;
202193

203194
Ok(FactoryReset {

0 commit comments

Comments
 (0)