Fix templates not being copied with correct file permission flags

main
trivernis 9 months ago
parent 1493797ace
commit d53decaf7b
Signed by: Trivernis
GPG Key ID: 7E6D18B61C8D2F4B

@ -54,6 +54,18 @@ impl FsAccess for BufferedFsAccess {
Ok(())
}
fn set_permissions(&mut self, path: &Path, perm: fs::Permissions) -> Result<()> {
let found_entry = self.mappings.iter().find(|(_, p)| p == path);
if let Some(entry) = found_entry {
fs::set_permissions(entry.0.path(), perm.clone())
.into_diagnostic()
.with_context(|| format!("Failed to set permissions {perm:?} on {path:?}"))?;
}
Ok(())
}
fn persist(&mut self) -> Result<()> {
let mappings = mem::take(&mut self.mappings);
let mut drop_list = Vec::new();

@ -1,5 +1,5 @@
use miette::Result;
use std::path::Path;
use std::{fs::Permissions, path::Path};
mod buffered;
pub use buffered::BufferedFsAccess;
@ -11,6 +11,9 @@ pub trait FsAccess {
/// Copy src to dst
fn copy(&mut self, src: &Path, dst: &Path) -> Result<()>;
/// Sets permissions on a file
fn set_permissions(&mut self, path: &Path, perm: Permissions) -> Result<()>;
/// Persist the changes if necessary
fn persist(&mut self) -> Result<()>;
}

@ -156,7 +156,9 @@ impl FileEntry {
let dest = cwd.join(filename);
let render_contents = templating::render(&contents, &ctx.config.template_context)?;
ctx.fs.write_all(&dest, &render_contents.into_bytes())?
ctx.fs.write_all(&dest, &render_contents.into_bytes())?;
ctx.fs
.set_permissions(&dest, fs::metadata(path).into_diagnostic()?.permissions())?;
}
FileEntry::Plain(path) => {
let filename = path.file_name().unwrap();

Loading…
Cancel
Save