From 5a444584eddc8889a28778a0acb13e34d78d8762 Mon Sep 17 00:00:00 2001 From: "Brian L. Troutwine" Date: Thu, 2 Nov 2023 14:03:35 -0700 Subject: [PATCH] wire up configuration, review feedback Signed-off-by: Brian L. Troutwine --- lading/src/generator/file_gen.rs | 9 +++++++++ lading/src/generator/file_gen/logrotate.rs | 10 +++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lading/src/generator/file_gen.rs b/lading/src/generator/file_gen.rs index b68e07a3f..c7b8a40cf 100644 --- a/lading/src/generator/file_gen.rs +++ b/lading/src/generator/file_gen.rs @@ -29,6 +29,9 @@ pub enum Error { /// Wrapper around [`traditional::Error`]. #[error(transparent)] Traditional(#[from] traditional::Error), + /// Wrapper around [`logrotate::Error`]. + #[error(transparent)] + Logrotate(#[from] logrotate::Error), } /// Configuration of [`FileGen`] @@ -37,6 +40,8 @@ pub enum Error { pub enum Config { /// See [`traditional::Config`]. Traditional(traditional::Config), + /// See [`logrotate::Config`]. + Logrotate(logrotate::Config), } #[derive(Debug)] @@ -47,6 +52,8 @@ pub enum Config { pub enum FileGen { /// See [`traditional::Server`] for details. Traditional(traditional::Server), + /// See [`logrotate::Server`] for details. + Logrotate(logrotate::Server), } impl FileGen { @@ -66,6 +73,7 @@ impl FileGen { Config::Traditional(c) => { Self::Traditional(traditional::Server::new(general, c, shutdown)?) } + Config::Logrotate(c) => Self::Logrotate(logrotate::Server::new(general, c, shutdown)?), }; Ok(srv) } @@ -85,6 +93,7 @@ impl FileGen { pub async fn spin(self) -> Result<(), Error> { match self { Self::Traditional(inner) => inner.spin().await?, + Self::Logrotate(inner) => inner.spin().await?, }; Ok(()) diff --git a/lading/src/generator/file_gen/logrotate.rs b/lading/src/generator/file_gen/logrotate.rs index c0bc4503a..1441d343b 100644 --- a/lading/src/generator/file_gen/logrotate.rs +++ b/lading/src/generator/file_gen/logrotate.rs @@ -237,7 +237,8 @@ impl Child { throttle: Throttle, shutdown: Shutdown, ) -> Self { - let mut names = Vec::with_capacity(total_rotations as usize); + let mut names = Vec::with_capacity((total_rotations + 1).into()); + names.push(PathBuf::from(basename)); for i in 0..total_rotations { let name = format!( "{orig}.{i}", @@ -265,9 +266,10 @@ impl Child { let maximum_bytes_per_log: u64 = u64::from(self.maximum_bytes_per_log.get()); let total_names = self.names.len(); - let last_name = &self.names[total_names]; + // SAFETY: By construction there is guaranteed to be at least one name. + let last_name = &self.names.last().unwrap(); - // SAFETY: By construction the name is guranteed to have a parent. + // SAFETY: By construction the name is guaranteed to have a parent. fs::create_dir_all(&self.names[0].parent().unwrap()).await?; let mut fp = BufWriter::with_capacity( bytes_per_second, @@ -288,6 +290,8 @@ impl Child { let bytes_written = register_counter!("bytes_written"); loop { + // SAFETY: By construction the block cache will never be empty + // except in the event of a catastrophic failure. let blk = rcv.peek().await.unwrap(); let total_bytes = blk.total_bytes;