Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve file mode API #170

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
### Breaking Changes

- Refactored the `FileOptions` functions. Instead of using `FileOptions::new(path)` to
construct a file to be added during a package build, instead you use `FileOptions::regular()`,
`FileOptions::dir()`, or `FileOptions::symlink()` for a regular file, directory, or symbolic
link, respectively.

- Support for symbolic link in file mode.
- Make file type const `REGULAR_FILE_TYPE` `DIR_FILE_TYPE` `SYMBOLIC_LINK_FILE_TYPE` public, because `FileMode::file_type` is public, sometimes we need this const to determin file type.
## Added

- Support for symbolic links when adding files to a `Package`.

## 0.12.1

### Added

- Support for setting file capabilities via the RPMTAGS_FILECAPS header.
- `PackageMetadata::get_file_entries` method can get capability headers for each file.
- When parsing packages, the `PackageMetadata::get_file_entries` method provides
access to the capabilities for each file.

## 0.12.0

Expand All @@ -30,10 +37,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
included by default and can be clamped using the `PackageBuilder::source_date` method.
- Several of the signer and verifier trait APIs were changed

Note: The pace of breaking changes ought to slow down significantly from this point forwards.
Most of the substantial changes which needed to be made have now been made. Thank you for your
patience.

### Added

- `PackageBuilder::source_date` method for clamping modification time of files,
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,31 @@ This library does not build software like rpmbuild. It is meant for finished art
use rpm::signature::pgp::{Signer, Verifier};

let raw_secret_key = std::fs::read("./test_assets/secret_key.asc")?;
// It's recommended to use timestamp of last commit in your VCS
// It's recommended to use timestamp of last commit in your VCS rather than a constant
let source_date = 1_600_000_000;
let pkg = rpm::PackageBuilder::new("test", "1.0.0", "MIT", "x86_64", "some awesome package")
.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::symlink("/usr/bin/awesome_link", "/usr/bin/awesome")
.permissions(0o644)
.pre_install_script("echo preinst")
Copy link
Collaborator Author

@dralley dralley Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drahnr Could you do a quick skim of these changes and let me know what you think? It still needs polish so don't spend too much time on it, just let me know if I'm doing something stupid.

// 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