use anyhow::Result;
use std::fs;
use std::path::{Path, PathBuf};
use tempfile::TempDir;
pub struct TempWorkspace {
temp_dir: TempDir,
}
impl TempWorkspace {
pub fn new() -> Result<Self> {
let temp_dir = TempDir::new()?;
Ok(Self { temp_dir })
}
#[must_use]
pub fn path(&self) -> &Path {
self.temp_dir.path()
}
pub fn write_config_file(&self, filename: &str, config: &str) -> Result<()> {
let file_path = self.temp_dir.path().join(filename);
fs::write(file_path, config)?;
Ok(())
}
#[allow(dead_code)]
pub fn write_file(&self, filename: &str, content: &str) -> Result<()> {
let file_path = self.temp_dir.path().join(filename);
fs::write(file_path, content)?;
Ok(())
}
#[must_use]
#[allow(dead_code)]
pub fn data_dir(&self) -> PathBuf {
self.temp_dir.path().join("data")
}
#[must_use]
#[allow(dead_code)]
pub fn build_dir(&self) -> PathBuf {
self.temp_dir.path().join("build")
}
}