Skip to main content

sentri_utils/
path_utils.rs

1//! Path utilities for cross-platform compatibility.
2
3use std::path::{Path, PathBuf};
4
5/// Normalize a path for the current platform.
6pub fn normalize_path(path: &Path) -> PathBuf {
7    path.to_path_buf()
8}
9
10/// Check if a path exists and is a file.
11pub fn is_file(path: &Path) -> bool {
12    path.is_file()
13}
14
15/// Check if a path exists and is a directory.
16pub fn is_dir(path: &Path) -> bool {
17    path.is_dir()
18}
19
20/// Ensure a directory exists, creating it if necessary.
21pub fn ensure_dir(path: &Path) -> std::io::Result<()> {
22    std::fs::create_dir_all(path)
23}
24
25/// Read a file to string safely.
26pub fn read_file(path: &Path) -> std::io::Result<String> {
27    std::fs::read_to_string(path)
28}
29
30/// Write a string to a file safely.
31pub fn write_file(path: &Path, content: &str) -> std::io::Result<()> {
32    std::fs::write(path, content)
33}