diff --git a/CHANGELOG.md b/CHANGELOG.md index 142a108..c12a816 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Dependency::config()`, `Dependency::user()`, `Dependency::group()` - `PackageBuilder::verify_script()` - `PackageBuilder::group()` and `PackageBuilder::packager()` +- `PackageBuilder::with_file_contents()` - Added support for the automatic user/group creation feature in rpm 4.19 ### Changed diff --git a/src/rpm/builder.rs b/src/rpm/builder.rs index 1b684b1..6180b44 100644 --- a/src/rpm/builder.rs +++ b/src/rpm/builder.rs @@ -363,6 +363,40 @@ impl PackageBuilder { Ok(self) } + /// Add a file to the package without needing an existing file. + /// + /// Helpful if files are being generated on-demand, and you don't want to write them to disk. + /// + /// ``` + /// # fn foo() -> Result<(), Box> { + /// + /// let pkg = rpm::PackageBuilder::new("foo", "1.0.0", "Apache-2.0", "x86_64", "some baz package") + /// .with_file_contents( + /// " + /// [check] + /// date = true + /// time = true + /// ", + /// rpm::FileOptions::new("/etc/awesome/config.toml").is_config(), + /// )? + /// .with_file_contents( + /// "./awesome-config.toml", + /// // you can set a custom mode, capabilities and custom user too + /// rpm::FileOptions::new("/etc/awesome/second.toml").mode(0o100744).caps("cap_sys_admin=pe")?.user("hugo"), + /// )? + /// .build()?; + /// # Ok(()) + /// # } + /// ``` + pub fn with_file_contents( + mut self, + content: impl Into>, + options: impl Into, + ) -> Result { + self.add_data(content.into(), Timestamp::now(), options.into())?; + Ok(self) + } + fn add_data( &mut self, content: Vec,