deamon finished
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
/target
|
||||
/.direnv
|
||||
/battery.data
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user