2024-04-27 20:31:23 +01:00
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
|
|
|
use tempfile::TempDir;
|
|
|
|
|
2024-10-30 08:52:42 +00:00
|
|
|
use super::real::FileSystem;
|
|
|
|
|
2024-04-27 20:31:23 +01:00
|
|
|
pub(super) fn new() -> super::Result<TempFileSystem> {
|
|
|
|
let temp_dir = tempfile::tempdir()?;
|
|
|
|
let base = temp_dir.path().to_path_buf();
|
|
|
|
let temp_dir = Arc::new(Mutex::new(temp_dir));
|
|
|
|
let real = super::real::new(base);
|
|
|
|
|
|
|
|
Ok(TempFileSystem {
|
|
|
|
real,
|
|
|
|
_temp_dir: temp_dir,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-04-30 07:44:08 +01:00
|
|
|
#[derive(Clone, Debug)]
|
2024-04-27 20:31:23 +01:00
|
|
|
pub struct TempFileSystem {
|
2024-10-30 08:52:42 +00:00
|
|
|
real: FileSystem,
|
2024-04-27 20:31:23 +01:00
|
|
|
_temp_dir: Arc<Mutex<TempDir>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::ops::Deref for TempFileSystem {
|
2024-10-30 08:52:42 +00:00
|
|
|
type Target = FileSystem;
|
2024-04-27 20:31:23 +01:00
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.real
|
|
|
|
}
|
|
|
|
}
|