use std::io::Write;
use std::path::Path;
pub fn write_private(path: &Path, contents: &str) -> std::io::Result<()> {
#[cfg(unix)]
{
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
let mut opts = std::fs::OpenOptions::new();
opts.write(true).create(true).truncate(true).mode(0o600);
let mut f = opts.open(path)?;
f.write_all(contents.as_bytes())?;
std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600))?;
Ok(())
}
#[cfg(not(unix))]
{
let mut f = std::fs::File::create(path)?;
f.write_all(contents.as_bytes())
}
}