2018-07-26 17:54:22 -04:00
|
|
|
use std;
|
|
|
|
use std::fs::File;
|
2018-08-22 13:19:32 -04:00
|
|
|
use std::io::Write;
|
2018-07-26 17:54:22 -04:00
|
|
|
use std::path::Path;
|
|
|
|
|
2018-08-22 13:19:32 -04:00
|
|
|
pub fn write_file_sync(path: &Path, content: &[u8]) -> std::io::Result<()> {
|
|
|
|
let mut f = File::create(path)?;
|
|
|
|
f.write_all(content)
|
|
|
|
}
|
|
|
|
|
2018-07-26 17:54:22 -04:00
|
|
|
pub fn mkdir(path: &Path) -> std::io::Result<()> {
|
|
|
|
debug!("mkdir -p {}", path.display());
|
|
|
|
assert!(path.has_root(), "non-has_root not yet implemented");
|
|
|
|
std::fs::create_dir_all(path).or_else(|err| {
|
|
|
|
if err.kind() == std::io::ErrorKind::AlreadyExists {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2018-08-23 03:58:59 -04:00
|
|
|
|
|
|
|
pub fn normalize_path(path: &Path) -> String {
|
|
|
|
let s = String::from(path.to_str().unwrap());
|
|
|
|
if cfg!(windows) {
|
|
|
|
// TODO This isn't correct. Probbly should iterate over components.
|
|
|
|
s.replace("\\", "/")
|
|
|
|
} else {
|
|
|
|
s
|
|
|
|
}
|
|
|
|
}
|