mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-16 01:42:55 +00:00
Fixes #4689 by replacing all of `std::Path` , `std::PathBuf` with `camino::Utf8Path`, `camino::Utf8PathBuf` in - pageserver - safekeeper - control_plane - libs/remote_storage Co-authored-by: Joonas Koivunen <joonas@neon.tech>
37 lines
825 B
Rust
37 lines
825 B
Rust
use bytes::Bytes;
|
|
use camino::Utf8PathBuf;
|
|
use std::{
|
|
fs::{create_dir_all, File},
|
|
io::{BufWriter, Write},
|
|
};
|
|
|
|
pub struct Tracer {
|
|
writer: BufWriter<File>,
|
|
}
|
|
|
|
impl Drop for Tracer {
|
|
fn drop(&mut self) {
|
|
self.flush()
|
|
}
|
|
}
|
|
|
|
impl Tracer {
|
|
pub fn new(path: Utf8PathBuf) -> Self {
|
|
let parent = path.parent().expect("failed to parse parent path");
|
|
create_dir_all(parent).expect("failed to create trace dir");
|
|
|
|
let file = File::create(path).expect("failed to create trace file");
|
|
Tracer {
|
|
writer: BufWriter::new(file),
|
|
}
|
|
}
|
|
|
|
pub fn trace(&mut self, msg: &Bytes) {
|
|
self.writer.write_all(msg).expect("failed to write trace");
|
|
}
|
|
|
|
pub fn flush(&mut self) {
|
|
self.writer.flush().expect("failed to flush trace file");
|
|
}
|
|
}
|