Skip to main content

cmake_tidy/
coverage_excluded.rs

1use std::fs::{self, DirEntry, Metadata, ReadDir};
2use std::path::Path;
3
4use anyhow::{Context, Result};
5
6pub fn read_cmake_file(path: &Path) -> Result<String> {
7    fs::read_to_string(path)
8        .with_context(|| format!("failed to read CMake file: {}", path.display()))
9}
10
11pub fn write_fixed_file(path: &Path, fixed: &str) -> Result<()> {
12    fs::write(path, fixed)
13        .with_context(|| format!("failed to write fixed file: {}", path.display()))
14}
15
16pub fn write_formatted_file(path: &Path, output: String) -> Result<()> {
17    fs::write(path, output)
18        .with_context(|| format!("failed to write formatted file: {}", path.display()))
19}
20
21pub fn read_metadata(path: &Path) -> Result<Metadata> {
22    fs::metadata(path).with_context(|| format!("failed to read file metadata: {}", path.display()))
23}
24
25pub fn read_directory(path: &Path) -> Result<ReadDir> {
26    fs::read_dir(path).with_context(|| format!("failed to read directory: {}", path.display()))
27}
28
29pub fn read_directory_entry(entry: std::io::Result<DirEntry>, path: &Path) -> Result<DirEntry> {
30    entry.with_context(|| format!("failed to read entry in {}", path.display()))
31}