Skip to content

Commit

Permalink
Add FileEntry::linkto for symbolic links
Browse files Browse the repository at this point in the history
  • Loading branch information
marxin committed Oct 24, 2023
1 parent 60d26da commit ca8ea0c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
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.
- Added the `FileEntry.linkto` field that is a target of a symbolic link.

## 0.12.1

Expand Down
2 changes: 2 additions & 0 deletions src/rpm/headers/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ pub struct FileEntry {
pub digest: Option<FileDigest>,
/// Defines any capabilities on the file.
pub caps: Option<String>,
/// Defines a target of a symlink (if the file is a symbolic link).
pub linkto: String,
}

fn parse_entry_data_number<'a, T, E, F>(
Expand Down
16 changes: 13 additions & 3 deletions src/rpm/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,13 @@ impl PackageMetadata {
Err(Error::TagNotFound(_)) => Ok(None),
Err(e) => return Err(e),
};
let links = self
.header
.get_entry_data_as_string_array(IndexTag::RPMTAG_FILELINKTOS);

match (modes, users, groups, digests, mtimes, sizes, flags, caps) {
match (
modes, users, groups, digests, mtimes, sizes, flags, caps, links,
) {
(
Ok(modes),
Ok(users),
Expand All @@ -854,6 +859,7 @@ impl PackageMetadata {
Ok(sizes),
Ok(flags),
Ok(caps),
Ok(links),
) => {
let paths = self.get_file_paths()?;
let n = paths.len();
Expand All @@ -867,11 +873,12 @@ impl PackageMetadata {
mtimes,
sizes,
flags,
links,
))
.enumerate()
.try_fold::<Vec<FileEntry>, _, Result<_, Error>>(
Vec::with_capacity(n),
|mut acc, (idx, (path, user, group, mode, digest, mtime, size, flags))| {
|mut acc, (idx, (path, user, group, mode, digest, mtime, size, flags, linkto))| {
let digest = if digest.is_empty() {
None
} else {
Expand All @@ -893,6 +900,7 @@ impl PackageMetadata {
flags: FileFlags::from_bits_retain(flags),
size: size as usize,
caps: cap,
linkto: linkto.to_string(),
});
Ok(acc)
},
Expand All @@ -908,8 +916,9 @@ impl PackageMetadata {
Err(Error::TagNotFound(_)),
Err(Error::TagNotFound(_)),
Err(Error::TagNotFound(_)),
Err(Error::TagNotFound(_)),
) => Ok(vec![]),
(modes, users, groups, digests, mtimes, sizes, flags, caps) => {
(modes, users, groups, digests, mtimes, sizes, flags, caps, links) => {
modes?;
users?;
groups?;
Expand All @@ -918,6 +927,7 @@ impl PackageMetadata {
sizes?;
flags?;
caps?;
links?;
unreachable!()
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ fn test_rpm_header() -> Result<(), Box<dyn std::error::Error>> {

// Verify that if there are no capabilities set then the caps field is None
package.metadata.get_file_entries()?.iter().for_each(|f| {
match f.mode {
FileMode::SymbolicLink { permissions: _ } => match f.path.to_str().unwrap() {
"/usr/lib64/dirsrv/libldaputil.so" => assert_eq!("libldaputil.so.0.0.0", f.linkto),
"/usr/lib64/dirsrv/libslapd.so" => assert_eq!("libslapd.so.0.1.0", f.linkto),
_ => {}
},
_ => match f.path.to_str().unwrap() {
"/usr/share/man/man3/sds_ht_slot.3.gz" => assert_eq!("", f.linkto),
_ => {}
},
}

assert_eq!(f.clone().caps, None);
});

Expand Down

0 comments on commit ca8ea0c

Please sign in to comment.