Skip to content

Commit

Permalink
Tidy up some clippy allows in logrotate_fs (#1071)
Browse files Browse the repository at this point in the history
### What does this PR do?

This commit does not change the mechanism but it does largely improve
documentation.
  • Loading branch information
blt authored Oct 29, 2024
1 parent 0229a82 commit d92f425
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions lading/src/generator/file_gen/logrotate_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@
#![allow(clippy::cast_sign_loss)] // TODO remove these clippy allows
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::cast_possible_wrap)]
#![allow(missing_docs)]
#![allow(clippy::missing_panics_doc)]
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::needless_pass_by_value)]

use crate::generator;
use fuser::{
spawn_mount2, BackgroundSession, FileAttr, Filesystem, MountOption, ReplyAttr, ReplyData,
ReplyDirectory, ReplyEntry, Request,
};
use lading_payload::block;
use rand::{rngs::SmallRng, SeedableRng};
use tokio::task;
use tracing::{error, info};
// use lading_payload::block;
use crate::generator;
use nix::libc::{self, ENOENT};
use rand::{rngs::SmallRng, SeedableRng};
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
Expand All @@ -28,6 +21,8 @@ use std::{
sync::{Arc, Mutex, MutexGuard},
time::Duration,
};
use tokio::task::{self, JoinError};
use tracing::{error, info};

mod model;

Expand Down Expand Up @@ -74,6 +69,9 @@ pub enum Error {
/// Failed to convert, value is 0
#[error("Value provided must not be zero")]
Zero,
/// Could not join on task
#[error("Could not join on task: {0}")]
Join(#[from] JoinError),
}

#[derive(Debug)]
Expand All @@ -84,22 +82,25 @@ pub enum Error {
/// to the target _but_ keeps track of how many bytes are written and read
/// during operation.
pub struct Server {
// handles: Vec<JoinHandle<Result<(), Error>>>,
shutdown: lading_signal::Watcher,
background_session: BackgroundSession,
}

impl Server {
/// Create a new instances of `Server`
///
/// # Errors
///
/// Function will error if block cache cannot be built.
///
/// # Panics
///
/// Function will panic if the filesystem cannot be started.
pub fn new(
_: generator::General,
config: Config,
shutdown: lading_signal::Watcher,
) -> Result<Self, Error> {
// TODO spawn a filesystem thread here and not in spin but bubble up any
// errors and make it so that spin waits for the FS thread and also for
// the shutdown signal. We have a synchronous try_recv on the Watcher
// but the way that fuser runs it just blocks the thread and there's no
// place to poll.
let mut rng = SmallRng::from_seed(config.seed);

let total_bytes =
Expand Down Expand Up @@ -148,11 +149,16 @@ impl Server {

#[allow(clippy::cast_precision_loss)]
#[allow(clippy::cast_possible_truncation)]
/// Run the `Server` to completion
///
/// # Errors
///
/// Function will error if it cannot join on filesystem thread.
pub async fn spin(self) -> Result<(), Error> {
self.shutdown.recv().await;

let handle = task::spawn_blocking(|| self.background_session.join());
let _ = handle.await;
let () = handle.await?;

Ok(())
}
Expand Down

0 comments on commit d92f425

Please sign in to comment.