Add and prepare rust worker management system for file information processing and knowledge base framework

This commit is contained in:
Christbru 2025-10-19 03:53:02 -05:00
commit da6ab3a782
12 changed files with 1402 additions and 251 deletions

View file

@ -0,0 +1,34 @@
use anyhow::Result;
use std::fs;
use std::io::Write;
use std::path::{Path, PathBuf};
pub fn storage_dir() -> PathBuf {
std::env::var("ASTRA_STORAGE")
.map(PathBuf::from)
.unwrap_or_else(|_| std::env::current_dir().unwrap().join("storage"))
}
pub fn ensure_storage_dir() -> Result<()> {
let dir = storage_dir();
if !dir.exists() {
fs::create_dir_all(&dir)?;
}
Ok(())
}
pub fn save_file(filename: &str, contents: &[u8]) -> Result<PathBuf> {
ensure_storage_dir()?;
let mut path = storage_dir();
path.push(filename);
let mut f = fs::File::create(&path)?;
f.write_all(contents)?;
Ok(path)
}
pub fn delete_file(path: &Path) -> Result<()> {
if path.exists() {
fs::remove_file(path)?;
}
Ok(())
}