more log subcommands

This commit is contained in:
Mikaël Cluseau
2025-07-20 22:30:10 +02:00
parent b1bf8f3fb8
commit 52c23653ac
3 changed files with 109 additions and 47 deletions

View File

@ -35,7 +35,7 @@ impl<'t> Logger<'t> {
let archives_read_dir = (fs::read_dir(archives_path).await)
.map_err(|e| format_err!("failed to list archives: {e}"))?;
let mut prev_stamp = ts_trunc(Utc::now());
let mut prev_stamp = trunc_ts(Utc::now());
let mut current_log = BufWriter::new(self.open_log(prev_stamp).await?);
tokio::spawn(compress_archives(
@ -94,7 +94,7 @@ impl<'t> Logger<'t> {
prev_stamp: &mut Timestamp,
out: &mut BufWriter<File>,
) -> Result<()> {
let trunc_ts = ts_trunc(log.ts);
let trunc_ts = trunc_ts(log.ts);
if *prev_stamp < trunc_ts {
// switch log
out.flush().await?;
@ -193,7 +193,7 @@ async fn copy(
}
}
fn ts_trunc(ts: Timestamp) -> Timestamp {
pub fn trunc_ts(ts: Timestamp) -> Timestamp {
ts.duration_trunc(TRUNC_DELTA)
.expect("duration_trunc failed")
}
@ -331,12 +331,12 @@ impl PartialOrd for LogFile {
impl LogFile {
pub async fn copy_to(&self, out: &mut (impl AsyncWrite + Unpin)) -> io::Result<u64> {
let mut input = File::open(&self.path).await?;
let input = &mut File::open(&self.path).await?;
if self.compressed {
let mut out = ZstdDecoder::new(out);
tokio::io::copy(&mut input, &mut out).await
let out = &mut ZstdDecoder::new(out);
tokio::io::copy(input, out).await
} else {
tokio::io::copy(&mut input, out).await
tokio::io::copy(input, out).await
}
}
}