Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
fix: set permissions of pages files
Lars Wirzenius committed 7 months ago
commit a5849ecd317dd48fc90a2101bd1179966d61967e
parent 62f1ded
1 file changed +7 -0
modified src/util.rs
@@ -1,5 +1,7 @@
use std::{
+
    fs::Permissions,
    io::Write,
+
    os::unix::fs::PermissionsExt,
    path::{Path, PathBuf},
    str::FromStr,
};
@@ -149,6 +151,8 @@ pub fn safely_overwrite<P: AsRef<Path>>(filename: P, data: &[u8]) -> Result<(),
        .map_err(|err| UtilError::CreateTemp(dirname.to_path_buf(), err))?;
    tmp.write_all(data)
        .map_err(|err| UtilError::WriteTemp(dirname.to_path_buf(), err))?;
+
    let mode = Permissions::from_mode(0o644);
+
    std::fs::set_permissions(tmp.path(), mode).map_err(UtilError::TempPerm)?;
    tmp.persist(filename)
        .map_err(|err| UtilError::RenameTemp(filename.to_path_buf(), err))?;
    Ok(())
@@ -204,6 +208,9 @@ pub enum UtilError {
    #[error("failed to write to temporary file in {0}")]
    WriteTemp(PathBuf, #[source] std::io::Error),

+
    #[error("failed to set permissions on temporary file")]
+
    TempPerm(#[source] std::io::Error),
+

    #[error("failed to rename temporary file to {0}")]
    RenameTemp(PathBuf, #[source] tempfile::PersistError),
}