diff --git a/src/config/file.rs b/src/config/file.rs index 2696b48af1..5d4783b6ba 100644 --- a/src/config/file.rs +++ b/src/config/file.rs @@ -1,5 +1,9 @@ use std::fmt::Display; +fn is_false(value: &bool) -> bool { + !*value +} + #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct FileConfig { pub path: String, @@ -15,6 +19,8 @@ pub struct FileConfig { pub recursive_chown: bool, #[serde(default)] pub postinstall: bool, + #[serde(default, skip_serializing_if = "is_false")] + pub append: bool, } impl FileConfig { @@ -68,6 +74,9 @@ impl Display for FileConfig { if self.postinstall { write!(f, "!")?; } + if self.append { + write!(f, " append=yes")?; + } } if let Some(uid) = self.uid { write!(f, " uid={}", uid)?; diff --git a/src/config/file_impl.rs b/src/config/file_impl.rs index 361e2642ef..d39639f8ca 100644 --- a/src/config/file_impl.rs +++ b/src/config/file_impl.rs @@ -60,9 +60,19 @@ impl crate::FileConfig { })?; Ok(()) } else { - println!("Create file {}", target_file.display()); - let mut file = File::create(&target_file) - .with_context(|| format!("failed to create file {}", target_file.display()))?; + let action = if self.append { "Append" } else { "Create" }; + println!("{action} file {}", target_file.display()); + + let mut file = if self.append { + fs::OpenOptions::new() + .create(true) + .append(true) + .open(&target_file) + .with_context(|| format!("failed to append file {}", target_file.display()))? + } else { + File::create(&target_file) + .with_context(|| format!("failed to create file {}", target_file.display()))? + }; file.write_all(self.data.as_bytes())?; self.apply_perms(target_file)