You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.0 KiB

use std::fs::{metadata, set_permissions, File};
use std::io::{BufWriter, Write};
use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;
use crate::config::Config;
use crate::error::{MkrootError, MkrootResult};
pub fn os_release(config: &Config) -> MkrootResult<()> {
let mut path = PathBuf::from(&config.root_dir);
path.push("etc/os-release");
if config.verbose {
println!("Creating file {}", &path.display());
}
{
let f = File::create(&path)?;
let mut writer = BufWriter::new(f);
writer.write_fmt(format_args!(
"NAME=\"{}\"\nVERSION=\"{}\"\n",
&config.osname, &config.osversion
))?;
}
match metadata(&path) {
Ok(meta) => {
let mut perms = meta.permissions();
perms.set_mode(0o644);
if let Err(e) = set_permissions(&path, perms) {
return Err(MkrootError::from(format!(
"Error setting permissions {}: {}",
&path.display(),
e
)));
}
}
Err(e) => {
return Err(MkrootError::from(format!(
"Error reading metadata {}: {}",
&path.display(),
e
)))
}
}
Ok(())
}