Skip to content

Commit

Permalink
Improve the FileMode API
Browse files Browse the repository at this point in the history
Avoid users needing to deal with raw u16 numbers and return errors on
invalid values rather than making "invalid" part of the enum.
  • Loading branch information
dralley committed Aug 25, 2023
1 parent 90f55d0 commit f9f0ca9
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 193 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,25 @@ 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::regular("/etc/awesome/config.toml").is_config(),
)?
// file mode is inherited from source file
.with_file(
"./test_assets/awesome.py",
rpm::FileOptions::new("/usr/bin/awesome"),
rpm::FileOptions::regular("/usr/bin/awesome"),
)?
.with_file(
"./test_assets/awesome.toml",
// you can set a custom mode and custom user too
rpm::FileOptions::new("/etc/awesome/second.toml")
.mode(rpm::FileMode::regular(0o644))
rpm::FileOptions::regular("/etc/awesome/second.toml")
.permissions(0o644)
.caps("cap_sys_admin,cap_net_admin=pe")?
.user("hugo"),
)?
.with_file(
"./test_assets/empty_file_for_symlink_create",
rpm::FileOptions::new("/usr/bin/awesome_link")
.mode(0o120644)
.symlink("/usr/bin/awesome"),
rpm::FileOptions::symlink("/usr/bin/awesome_link", "/usr/bin/awesome")
.permissions(0o644)
.pre_install_script("echo preinst")
// If you don't need reproducible builds,
// you can remove the following line
Expand Down
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ bitflags! {
// const SPECFILE = 1 << 5; // first file in SRPM?
const GHOST = 1 << 6; // %%ghost
const LICENSE = 1 << 7; // %%license
const README = 1 << 8; // %%readme
const README = 1 << 8; // %%readme // obsolete?
// bits 9-10 unused
const PUBKEY = 1 << 11; // %%pubkey
const ARTIFACT = 1 << 12; // %%artifact
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
//! .compression(rpm::CompressionType::Gzip)
//! .with_file(
//! "./test_assets/awesome.toml",
//! rpm::FileOptions::new("/etc/awesome/config.toml").is_config(),
//! rpm::FileOptions::regular("/etc/awesome/config.toml").is_config(),
//! )?
//! // file mode is inherited from source file
//! .with_file(
//! "./test_assets/awesome.py",
//! rpm::FileOptions::new("/usr/bin/awesome"),
//! rpm::FileOptions::regular("/usr/bin/awesome"),
//! )?
//! .with_file(
//! "./test_assets/awesome.toml",
//! // you can set a custom mode and custom user too
//! rpm::FileOptions::new("/etc/awesome/second.toml")
//! .mode(rpm::FileMode::regular(0o644))
//! rpm::FileOptions::regular("/etc/awesome/second.toml")
//! .permissions(0o644)
//! .user("hugo"),
//! )?
//! .pre_install_script("echo preinst")
Expand Down
8 changes: 4 additions & 4 deletions src/rpm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,17 @@ impl PackageBuilder {
/// let pkg = rpm::PackageBuilder::new("foo", "1.0.0", "Apache-2.0", "x86_64", "some baz package")
/// .with_file(
/// "./awesome-config.toml",
/// rpm::FileOptions::new("/etc/awesome/config.toml").is_config(),
/// rpm::FileOptions::regular("/etc/awesome/config.toml").is_config(),
/// )?
/// // file mode is inherited from source file
/// .with_file(
/// "./awesome-bin",
/// rpm::FileOptions::new("/usr/bin/awesome"),
/// rpm::FileOptions::regular("/usr/bin/awesome"),
/// )?
/// .with_file(
/// "./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"),
/// rpm::FileOptions::regular("/etc/awesome/second.toml").permissions(0o744).caps("cap_sys_admin=pe")?.user("hugo"),
/// )?
/// .build()?;
/// # Ok(())
Expand All @@ -290,7 +290,7 @@ impl PackageBuilder {
input.read_to_end(&mut content)?;
let mut options = options.into();
if options.inherit_permissions {
options.mode = (file_mode(&input)? as i32).into();
options.mode = (file_mode(&input)? as i32).try_into()?;
}

let modified_at = input.metadata()?.modified()?.try_into()?;
Expand Down
Loading

0 comments on commit f9f0ca9

Please sign in to comment.