vv_agent/runtime/processes/
output.rs1use std::fs::{self, File, OpenOptions};
2use std::path::{Path, PathBuf};
3use std::sync::atomic::{AtomicU64, Ordering};
4
5use crate::workspace::read_captured_text_prefix;
6
7static PROCESS_COUNTER: AtomicU64 = AtomicU64::new(1);
8
9pub(super) fn next_output_path() -> PathBuf {
10 let counter = PROCESS_COUNTER.fetch_add(1, Ordering::Relaxed);
11 std::env::temp_dir().join(format!(
12 "vv_agent_process_{}_{}.log",
13 std::process::id(),
14 counter
15 ))
16}
17
18pub(super) fn open_output_file(path: &Path) -> std::io::Result<File> {
19 OpenOptions::new()
20 .create_new(true)
21 .write(true)
22 .read(true)
23 .open(path)
24}
25
26pub fn read_captured_output(path: &Path, limit_chars: usize) -> String {
27 read_captured_text_prefix(path, limit_chars)
28}
29
30pub fn remove_captured_output(path: &Path) {
31 let _ = fs::remove_file(path);
32}