25 lines
934 B
Rust
25 lines
934 B
Rust
//! Filesystem tools for the agent
|
|
//!
|
|
//! Port of `agent_fs_tools.c` / `agent_fs_tools.h` from the C project.
|
|
|
|
/// Read a file and return its contents.
|
|
pub fn agent_fs_read_file(path: &str) -> Result<String, String> {
|
|
std::fs::read_to_string(path).map_err(|e| format!("Failed to read file: {}", e))
|
|
}
|
|
|
|
/// Write content to a file.
|
|
pub fn agent_fs_write_file(path: &str, content: &str) -> Result<(), String> {
|
|
std::fs::write(path, content).map_err(|e| format!("Failed to write file: {}", e))
|
|
}
|
|
|
|
/// List files in a directory.
|
|
pub fn agent_fs_list_dir(path: &str) -> Result<Vec<String>, String> {
|
|
let entries = std::fs::read_dir(path).map_err(|e| format!("Failed to list directory: {}", e))?;
|
|
let mut files = Vec::new();
|
|
for entry in entries {
|
|
let entry = entry.map_err(|e| format!("Failed to read entry: {}", e))?;
|
|
files.push(entry.file_name().to_string_lossy().to_string());
|
|
}
|
|
Ok(files)
|
|
}
|