wasmer_cli/commands/journal/
compact.rs

1use std::path::PathBuf;
2
3use clap::Parser;
4use wasmer_wasix::journal::{
5    CompactingLogFileJournal, LogFileJournal, PrintingJournal, copy_journal,
6};
7
8use crate::commands::CliCommand;
9
10/// Compacts a journal by removing duplicate or redundant
11/// events and rewriting the log
12#[derive(Debug, Parser)]
13pub struct CmdJournalCompact {
14    /// Path to the journal that will be compacted
15    #[clap(index = 1)]
16    journal_path: PathBuf,
17}
18
19impl CliCommand for CmdJournalCompact {
20    type Output = ();
21
22    fn run(self) -> Result<(), anyhow::Error> {
23        let compactor = CompactingLogFileJournal::new(&self.journal_path)?.with_compact_on_drop();
24        drop(compactor);
25
26        let journal = LogFileJournal::new(&self.journal_path)?;
27        let printer = PrintingJournal::default();
28        copy_journal(&journal, &printer)?;
29        Ok(())
30    }
31}