Skip to main content

write_file_atomic_with_context

Function write_file_atomic_with_context 

Source
pub async fn write_file_atomic_with_context(
    path: &Path,
    content: &str,
    context: &str,
) -> Result<()>
Expand description

Write a file atomically with a contextual error message, ensuring the parent directory exists.

The content is first written to a temporary file created in the same directory as path (so the final rename stays on the same filesystem and is therefore atomic), then the temp file is renamed onto path. This prevents concurrent readers – e.g. another vtcode process sharing the same workspace – from ever observing a partially written file.

On rename failure the temp file is best-effort removed before returning the error.