Skip to content

Commit

Permalink
Add %config(noreplace) file attribute to builder
Browse files Browse the repository at this point in the history
Add method `is_no_replace` to `FileOptionsBuilder`, used to set
the `%config(noreplace)` flag on a file
  • Loading branch information
olivierlemasle authored and dralley committed Oct 21, 2023
1 parent 7b57c91 commit 60d26da
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
to the `summary`.
- Add method `with_key_passphrase` to `signature::pgp::Signer`, to provide the
passphrase when the PGP secret key is passphrase-protected.
- Add method `is_no_replace` to `FileOptionsBuilder`, used to set the
`%config(noreplace)` flag on a file.

## 0.12.1

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ let pkg = rpm::PackageBuilder::new("test", "1.0.0", "MIT", "x86_64", "some aweso
.compression(rpm::CompressionType::Gzip)
.with_file(
"./test_assets/awesome.toml",
rpm::FileOptions::new("/etc/awesome/config.toml").is_config(),
rpm::FileOptions::new("/etc/awesome/config.toml")
.is_config()
.is_no_replace(),
)?
// file mode is inherited from source file
.with_file(
Expand Down
15 changes: 10 additions & 5 deletions src/rpm/headers/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,27 +260,32 @@ impl FileOptionsBuilder {
}

pub fn is_doc(mut self) -> Self {
self.inner.flag = FileFlags::DOC;
self.inner.flag.insert(FileFlags::DOC);
self
}

pub fn is_config(mut self) -> Self {
self.inner.flag = FileFlags::CONFIG;
self.inner.flag.insert(FileFlags::CONFIG);
self
}

pub fn is_no_replace(mut self) -> Self {
self.inner.flag.insert(FileFlags::NOREPLACE);
self
}

pub fn is_ghost(mut self) -> Self {
self.inner.flag = FileFlags::GHOST;
self.inner.flag.insert(FileFlags::GHOST);
self
}

pub fn is_license(mut self) -> Self {
self.inner.flag = FileFlags::LICENSE;
self.inner.flag.insert(FileFlags::LICENSE);
self
}

pub fn is_readme(mut self) -> Self {
self.inner.flag = FileFlags::README;
self.inner.flag.insert(FileFlags::README);
self
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ However, it does nothing.",
.compression(rpm::CompressionType::Gzip)
.with_file(
"Cargo.toml",
FileOptions::new("/etc/awesome/config.toml").is_config(),
FileOptions::new("/etc/awesome/config.toml")
.is_config()
.is_no_replace(),
)?
// file mode is inherited from source file
.with_file("Cargo.toml", FileOptions::new("/usr/bin/awesome"))?
Expand Down Expand Up @@ -67,6 +69,7 @@ However, it does nothing.",
assert_eq!(f.ownership.user, "hugo".to_string());
} else if f.path.as_os_str() == "/etc/awesome/config.toml" {
assert_eq!(f.caps, Some("".to_string()));
assert_eq!(f.flags, FileFlags::CONFIG | FileFlags::NOREPLACE);
} else if f.path.as_os_str() == "/usr/bin/awesome" {
assert_eq!(f.mode, FileMode::from(0o100644));
} else if f.path.as_os_str() == "/usr/bin/awesome_link" {
Expand Down
3 changes: 2 additions & 1 deletion tests/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ mod pgp {
cargo_file.to_str().unwrap(),
FileOptions::new("/etc/foobar/hugo/bazz.toml")
.mode(0o100_777)
.is_config(),
.is_config()
.is_no_replace(),
)?
.with_file(
cargo_file.to_str().unwrap(),
Expand Down

0 comments on commit 60d26da

Please sign in to comment.