deamon finished

This commit is contained in:
2026-03-16 20:47:47 +00:00
parent 9c38717a40
commit 57be264701
2 changed files with 6 additions and 2 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
/target
/.direnv
/battery.data

View File

@@ -2,6 +2,7 @@ use std::{
error::Error,
fs,
io::{Read, Write},
os::unix::fs::FileExt,
thread::sleep,
time::{Duration, SystemTime},
};
@@ -30,6 +31,7 @@ fn main() -> Result<(), Box<dyn Error>> {
Err(err) => {
let battery_file = fs::OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open("./battery.data");
let new_data = Data::new(battery.as_data().0);
@@ -41,6 +43,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let battery_file = fs::OpenOptions::new()
.write(true)
.append(false)
.open("./battery.data")
.unwrap();
loop {
@@ -57,8 +60,8 @@ fn main() -> Result<(), Box<dyn Error>> {
};
data.data_chunks.push(new_chunk);
let raw_data = rkyv::to_bytes::<rancor::Error>(&data).unwrap();
battery_file.try_clone()?.write_all(&raw_data)?;
battery_file.try_clone()?.write_all_at(&raw_data, 0)?;
sleep(Duration::from_secs(3));
sleep(Duration::from_secs(5));
}
}