kxio/src/fs/temp.rs
Paul Campbell fa4232de6b
All checks were successful
Rust / build (map[name:stable]) (push) Successful in 1m58s
Rust / build (map[name:nightly]) (push) Successful in 3m48s
Release Please / Release-plz (push) Successful in 35s
refactor: cleanup
2024-11-02 21:29:27 +00:00

31 lines
697 B
Rust

use std::sync::{Arc, Mutex};
use tempfile::TempDir;
use super::{Error, FileSystem};
#[derive(Clone, Debug)]
pub struct TempFileSystem {
real: FileSystem,
_temp_dir: Arc<Mutex<TempDir>>,
}
impl TempFileSystem {
pub fn new() -> super::Result<Self> {
let temp_dir = tempfile::tempdir().map_err(Error::Io)?;
let base = temp_dir.path().to_path_buf();
let temp_dir = Arc::new(Mutex::new(temp_dir));
let real = super::new(base);
Ok(Self {
real,
_temp_dir: temp_dir,
})
}
}
impl std::ops::Deref for TempFileSystem {
type Target = FileSystem;
fn deref(&self) -> &Self::Target {
&self.real
}
}