BinaryPackage

Struct BinaryPackage 

Source
pub struct BinaryPackage { /* private fields */ }
Expand description

A pkgsrc binary package with cached metadata.

This provides fast access to package metadata without re-reading the archive. The metadata is read once during BinaryPackage::open, and subsequent operations like BinaryPackage::archive or BinaryPackage::extract_to re-open the archive as needed.

§Example

use pkgsrc::archive::BinaryPackage;

// Fast metadata access
let pkg = BinaryPackage::open("package-1.0.tgz").unwrap();
println!("Name: {}", pkg.pkgname().unwrap_or("unknown"));
println!("Comment: {}", pkg.metadata().comment());

// Generate summary for repository
let summary = pkg.to_summary().unwrap();

// Extract files (re-reads archive)
pkg.extract_to("/usr/pkg").unwrap();

Implementations§

Source§

impl BinaryPackage

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open a package from a file path.

This reads only the metadata entries at the start of the archive, providing fast access to package information without decompressing the entire file.

Source

pub fn path(&self) -> &Path

Return the path to the package file.

Source

pub fn compression(&self) -> Compression

Return the compression format.

Source

pub fn archive_type(&self) -> ArchiveType

Return the archive type (signed or unsigned).

Source

pub fn is_signed(&self) -> bool

Return whether this package is signed.

Source

pub fn metadata(&self) -> &Metadata

Return the package metadata.

Source

pub fn plist(&self) -> &Plist

Return the packing list.

Source

pub fn pkgname(&self) -> Option<&str>

Return the package name from the plist.

Source

pub fn build_info(&self) -> &HashMap<String, Vec<String>>

Return the build info key-value pairs.

Source

pub fn build_info_value(&self, key: &str) -> Option<&str>

Get a specific build info value (first value if multiple exist).

Source

pub fn build_info_values(&self, key: &str) -> Option<&[String]>

Get all values for a build info key.

Source

pub fn pkg_hash(&self) -> Option<&PkgHash>

Return the package hash (for signed packages).

Source

pub fn gpg_signature(&self) -> Option<&[u8]>

Return the GPG signature (for signed packages).

Source

pub fn file_size(&self) -> u64

Return the file size of the package.

Source

pub fn archive(&self) -> Result<Archive<BufReader<File>>>

Open the archive for iteration (re-reads the file).

Source

pub fn extract_to(&self, dest: impl AsRef<Path>) -> Result<()>

Extract all files to a destination directory.

This re-reads the archive and extracts all entries.

Source

pub fn extract_with_plist( &self, dest: impl AsRef<Path>, options: ExtractOptions, ) -> Result<Vec<ExtractedFile>>

Extract files to a destination directory with plist-based permissions.

This method extracts files and applies permissions specified in the packing list (@mode, @owner, @group directives).

§Arguments
  • dest - Destination directory for extraction
  • options - Extraction options controlling mode/ownership application
§Returns

A vector of ExtractedFile describing each extracted file.

§Example
use pkgsrc::archive::{BinaryPackage, ExtractOptions};

let pkg = BinaryPackage::open("package-1.0.tgz").unwrap();
let options = ExtractOptions::new().with_mode();
let extracted = pkg.extract_with_plist("/usr/pkg", options).unwrap();
for file in &extracted {
    println!("Extracted: {}", file.path.display());
}
Source

pub fn verify_checksums( &self, dest: impl AsRef<Path>, ) -> Result<Vec<(PathBuf, String, String)>>

Verify checksums of extracted files against plist MD5 values.

This method checks that files in the destination directory match the MD5 checksums recorded in the packing list.

§Arguments
  • dest - Directory where files were extracted
§Returns

A vector of tuples containing (file_path, expected_hash, actual_hash) for files that failed verification. Empty vector means all passed.

Source

pub fn sign(&self, signature: &[u8]) -> Result<SignedArchive>

Sign this package.

Re-reads the package file to compute hashes and create a signed archive.

Source

pub fn to_summary(&self) -> Result<Summary>

Convert this package to a Summary entry.

This uses default options (no file checksum computation). Use to_summary_with_opts for more control.

Source

pub fn to_summary_with_opts(&self, opts: &SummaryOptions) -> Result<Summary>

Convert this package to a Summary entry with options.

§Example
use pkgsrc::archive::{BinaryPackage, SummaryOptions};

let pkg = BinaryPackage::open("package-1.0.tgz").unwrap();
let opts = SummaryOptions { compute_file_cksum: true };
let summary = pkg.to_summary_with_opts(&opts).unwrap();

Trait Implementations§

Source§

impl Debug for BinaryPackage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FileRead for BinaryPackage

Source§

fn pkgname(&self) -> &str

Package name including version (e.g., “foo-1.0”).
Source§

fn comment(&self) -> Result<String>

Package comment (+COMMENT). Single line description.
Source§

fn contents(&self) -> Result<String>

Package contents (+CONTENTS). The packing list.
Source§

fn desc(&self) -> Result<String>

Package description (+DESC). Multi-line description.
Source§

fn build_info(&self) -> Result<Option<String>>

Build information (+BUILD_INFO).
Source§

fn build_version(&self) -> Result<Option<String>>

Build version (+BUILD_VERSION).
Source§

fn deinstall(&self) -> Result<Option<String>>

Deinstall script (+DEINSTALL).
Source§

fn display(&self) -> Result<Option<String>>

Display file (+DISPLAY).
Source§

fn install(&self) -> Result<Option<String>>

Install script (+INSTALL).
Source§

fn installed_info(&self) -> Result<Option<String>>

Installed info (+INSTALLED_INFO).
Source§

fn mtree_dirs(&self) -> Result<Option<String>>

Mtree dirs (+MTREE_DIRS).
Source§

fn preserve(&self) -> Result<Option<String>>

Preserve file (+PRESERVE).
Source§

fn required_by(&self) -> Result<Option<String>>

Required by (+REQUIRED_BY).
Source§

fn size_all(&self) -> Result<Option<String>>

Total size including dependencies (+SIZE_ALL).
Source§

fn size_pkg(&self) -> Result<Option<String>>

Package size (+SIZE_PKG).
Source§

impl TryFrom<&BinaryPackage> for Summary

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(pkg: &BinaryPackage) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.