diff --git a/src/fs_access/buffered.rs b/src/fs_access/buffered.rs index 834c002..b3d0530 100644 --- a/src/fs_access/buffered.rs +++ b/src/fs_access/buffered.rs @@ -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(); diff --git a/src/fs_access/mod.rs b/src/fs_access/mod.rs index 612a51d..9a9b340 100644 --- a/src/fs_access/mod.rs +++ b/src/fs_access/mod.rs @@ -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<()>; } diff --git a/src/repo/contents.rs b/src/repo/contents.rs index 7a34c0d..3fb8e05 100644 --- a/src/repo/contents.rs +++ b/src/repo/contents.rs @@ -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();