create image output parent directory if nonexistent

This commit is contained in:
Ondrej Novak 2026-07-06 22:26:46 +02:00
parent 9025e0e461
commit 92196dcbf8
Signed by: handy
SSH Key Fingerprint: SHA256:jlNm8ijkaMl4X7+nn3zBFTJufdQgT4unKJoZVH6kYTM
1 changed files with 10 additions and 1 deletions

View File

@ -1,5 +1,5 @@
use core::fmt; use core::fmt;
use std::time::SystemTime; use std::{fs, time::SystemTime};
use draw::{StackedConfig, StackedSeries, StackedSeriesConfig, stacked}; use draw::{StackedConfig, StackedSeries, StackedSeriesConfig, stacked};
use imageproc::image::codecs::pnm::SampleEncoding; use imageproc::image::codecs::pnm::SampleEncoding;
@ -95,6 +95,15 @@ impl Runner {
self.last_sample = now; self.last_sample = now;
for g in &mut self.graphs { for g in &mut self.graphs {
let path = std::path::Path::new(&g.series.config.path)
.parent()
.expect("wrong target directory");
if !fs::exists(path).unwrap_or(false) {
fs::create_dir(path).map_err(|_| {
RunnerError::CouldNotSaveImage("cannot create parent directory".to_string())
})?;
}
// fill in empty samples for missing data // fill in empty samples for missing data
if dt >= 2. { if dt >= 2. {
let dt_round = dt.round() as u32; let dt_round = dt.round() as u32;