Skip to content

Commit

Permalink
fixup. cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusl committed Dec 10, 2023
1 parent e709f57 commit 474a813
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
22 changes: 11 additions & 11 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,15 @@ bitflags! {
/// Macro expansion,
///
/// Corresponds to RPMSCRIPT_FLAG_EXPAND
///
///
const EXPAND = 1;
/// Header queryformat expansion,
///
///
/// Corresponds to RPMSCRIPT_FLAG_QFORMAT
///
const QFORMAT = 1 << 1;
/// Critical for success/failure,
///
///
/// Corresponds to RPMSCRIPT_FLAG_CRITICAL
///
const CRITICAL = 1 << 2;
Expand Down Expand Up @@ -593,63 +593,63 @@ pub enum DigestAlgorithm {
}

/// Index tag values for the %prein scriptlet,
///
///
pub(crate) const PREIN_TAGS: ScriptletIndexTags = (
IndexTag::RPMTAG_PREIN,
IndexTag::RPMTAG_PREINFLAGS,
IndexTag::RPMTAG_PREINPROG,
);

/// Index tag values for the %postin scriptlet,
///
///
pub(crate) const POSTIN_TAGS: ScriptletIndexTags = (
IndexTag::RPMTAG_POSTIN,
IndexTag::RPMTAG_POSTINFLAGS,
IndexTag::RPMTAG_POSTINPROG,
);

/// Index tag values for the %preun scriptlet,
///
///
pub(crate) const PREUN_TAGS: ScriptletIndexTags = (
IndexTag::RPMTAG_PREUN,
IndexTag::RPMTAG_PREUNFLAGS,
IndexTag::RPMTAG_PREUNPROG,
);

/// Index tag values for the %postun scriptlet,
///
///
pub(crate) const POSTUN_TAGS: ScriptletIndexTags = (
IndexTag::RPMTAG_POSTUN,
IndexTag::RPMTAG_POSTUNFLAGS,
IndexTag::RPMTAG_POSTUNPROG,
);

/// Index tag values for the %pretrans scriptlet,
///
///
pub(crate) const PRETRANS_TAGS: ScriptletIndexTags = (
IndexTag::RPMTAG_PRETRANS,
IndexTag::RPMTAG_PRETRANSFLAGS,
IndexTag::RPMTAG_PRETRANSPROG,
);

/// Index tag values for the %posttrans scriptlet,
///
///
pub(crate) const POSTTRANS_TAGS: ScriptletIndexTags = (
IndexTag::RPMTAG_POSTTRANS,
IndexTag::RPMTAG_POSTTRANSFLAGS,
IndexTag::RPMTAG_POSTTRANSPROG,
);

/// Index tag values for the %preuntrans scriptlet,
///
///
pub(crate) const PREUNTRANS_TAGS: ScriptletIndexTags = (
IndexTag::RPMTAG_PREUNTRANS,
IndexTag::RPMTAG_PREUNTRANSFLAGS,
IndexTag::RPMTAG_PREUNTRANSPROG,
);

/// Index tag values for the %postuntrans scriptlet,
///
///
pub(crate) const POSTUNTRANS_TAGS: ScriptletIndexTags = (
IndexTag::RPMTAG_POSTUNTRANS,
IndexTag::RPMTAG_POSTUNTRANSFLAGS,
Expand Down
12 changes: 6 additions & 6 deletions src/rpm/headers/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ pub struct Scriptlet {

impl Scriptlet {
/// Returns a new scriplet,
///
///
#[inline]
pub fn new(script: impl Into<String>) -> Scriptlet {
Scriptlet {
Expand Down Expand Up @@ -598,13 +598,13 @@ mod test {
fn test_scriptlet_builder() {
// Test full state
let scriptlet = crate::Scriptlet::new(
r#"
r#"
echo `hello world`
"#
.trim(),
)
.flags(crate::ScriptletFlags::EXPAND)
.prog(vec!["/usr/bin/blah", "-c"]);
.trim(),
)
.flags(crate::ScriptletFlags::EXPAND)
.prog(vec!["/usr/bin/blah", "-c"]);

let mut records = vec![];
let offset = 0i32;
Expand Down
5 changes: 1 addition & 4 deletions src/rpm/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,7 @@ impl PackageMetadata {
}
}

fn get_scriptlet(
&self,
tags: ScriptletIndexTags,
) -> Result<Scriptlet, Error> {
fn get_scriptlet(&self, tags: ScriptletIndexTags) -> Result<Scriptlet, Error> {
let (scriptlet_tag, flags_tag, program_tag) = tags;

let script = self
Expand Down
24 changes: 12 additions & 12 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,8 @@ However, it does nothing.",
.symlink("/usr/bin/awesome"),
)?
.pre_install_script("echo preinst")
.post_install_script(
Scriptlet::new("echo postinst")
.prog(vec!["/bin/blah/bash", "-c"]),
)
.pre_trans_script(
Scriptlet::new("echo pretrans")
.flags(ScriptletFlags::EXPAND),
)
.post_install_script(Scriptlet::new("echo postinst").prog(vec!["/bin/blah/bash", "-c"]))
.pre_trans_script(Scriptlet::new("echo pretrans").flags(ScriptletFlags::EXPAND))
.post_trans_script(
Scriptlet::new("echo posttrans")
.flags(ScriptletFlags::EXPAND)
Expand Down Expand Up @@ -97,17 +91,20 @@ However, it does nothing.",
assert_eq!(f.mode, FileMode::from(0o120644));
}
});

// Test scriptlet builder fn branches
let preinst = pkg.metadata.get_pre_install_script()?;
assert_eq!(preinst.script.as_str(), "echo preinst");
assert!(preinst.flags.is_none());
assert!(preinst.program.is_none());

let postinst = pkg.metadata.get_post_install_script()?;
assert_eq!(postinst.script.as_str(), "echo postinst");
assert!(postinst.flags.is_none());
assert_eq!(postinst.program, Some(vec!["/bin/blah/bash".to_string(), "-c".to_string()]));
assert_eq!(
postinst.program,
Some(vec!["/bin/blah/bash".to_string(), "-c".to_string()])
);

let pretrans = pkg.metadata.get_pre_trans_script()?;
assert_eq!(pretrans.script.as_str(), "echo pretrans");
Expand All @@ -117,7 +114,10 @@ However, it does nothing.",
let posttrans = pkg.metadata.get_post_trans_script()?;
assert_eq!(posttrans.script.as_str(), "echo posttrans");
assert_eq!(posttrans.flags, Some(ScriptletFlags::EXPAND));
assert_eq!(posttrans.program, Some(vec!["/bin/blah/bash".to_string(), "-c".to_string()]));
assert_eq!(
posttrans.program,
Some(vec!["/bin/blah/bash".to_string(), "-c".to_string()])
);

assert!(pkg.metadata.get_pre_untrans_script().is_err());

Expand Down

0 comments on commit 474a813

Please sign in to comment.