1use std::path::{Path, PathBuf};
5
6use yog_ids::Format;
7
8pub(crate) fn of(dir: &Path, format: Format) -> Vec<PathBuf> {
10 yog_analysis::files::with_ext(dir, &[format.ext()])
11}
12
13pub fn read_source(path: impl AsRef<Path>) -> std::io::Result<String> {
16 let bytes = std::fs::read(path)?;
17 yog_data::source::text(&bytes)
18 .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
19}
20
21pub fn write_source(path: &Path, text: &str) -> Result<(), String> {
23 let bytes = yog_data::source::binary(text).map_err(|e| format!("{}: {e}", path.display()))?;
24 std::fs::write(path, bytes).map_err(|e| format!("{}: {e}", path.display()))
25}
26
27pub fn remove(path: &Path) {
30 let removed = if path.is_dir() {
31 std::fs::remove_dir_all(path)
32 } else {
33 std::fs::remove_file(path)
34 };
35 if let Err(e) = removed
36 && e.kind() != std::io::ErrorKind::NotFound
37 {
38 yog_logging::warn!("couldn't remove {}: {e}", path.display());
39 }
40}