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 /target
/.direnv /.direnv
/battery.data

View File

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