mirror of
https://github.com/italicsjenga/fh5-telemetry-watcher.git
synced 2024-12-23 14:11:33 +11:00
file permissions on unix & better verbose control
This commit is contained in:
parent
ec31317928
commit
b50a5e5211
18
src/main.rs
18
src/main.rs
|
@ -1,4 +1,7 @@
|
|||
use std::fs::OpenOptions;
|
||||
use std::net::UdpSocket;
|
||||
#[cfg(target_family = "unix")]
|
||||
use std::os::unix::fs::OpenOptionsExt;
|
||||
use std::path::Path;
|
||||
use std::{fs, net};
|
||||
|
||||
|
@ -191,22 +194,25 @@ fn main() {
|
|||
if deserialised.is_race_on == 0 {
|
||||
continue 'listener;
|
||||
}
|
||||
if args.verbose {}
|
||||
|
||||
if status.position != deserialised.race_position {
|
||||
status.position = deserialised.race_position;
|
||||
if args.verbose {
|
||||
println!("now position {}", status.position);
|
||||
}
|
||||
}
|
||||
|
||||
if status.inrace {
|
||||
if deserialised.race_position == 0 {
|
||||
// coming out of race
|
||||
status.inrace = false;
|
||||
writer.flush().expect("couldnt flush to file");
|
||||
if args.verbose {
|
||||
println!(
|
||||
"{}: no longer in race",
|
||||
&Local::now().format("%H:%M:%S").to_string()
|
||||
);
|
||||
}
|
||||
continue 'listener;
|
||||
} else {
|
||||
// still in race
|
||||
|
@ -215,15 +221,23 @@ fn main() {
|
|||
if deserialised.race_position > 0 {
|
||||
// getting into race
|
||||
status.inrace = true;
|
||||
if args.verbose {
|
||||
println!(
|
||||
"{}: entering race",
|
||||
&Local::now().format("%H:%M:%S").to_string()
|
||||
);
|
||||
println!("car class: {}", deserialised.car_performance_index);
|
||||
}
|
||||
let mut options = OpenOptions::new().write(true).create_new(true).clone();
|
||||
// open file with wide open permissions on unix systems
|
||||
if cfg!(target_family = "unix") {
|
||||
options.mode(0o777);
|
||||
}
|
||||
// open file for this race
|
||||
// filename format: timestamp _ car class _ car ordinal
|
||||
writer = csv::Writer::from_writer(
|
||||
fs::File::create(folder_path.join(format!(
|
||||
options
|
||||
.open(folder_path.join(format!(
|
||||
"{}_{}_{}{}",
|
||||
&Local::now().format("%Y-%m-%d_%H-%M").to_string(),
|
||||
deserialised.car_performance_index,
|
||||
|
|
Loading…
Reference in a new issue