pkgsrc

Struct Metadata

source
pub struct Metadata { /* private fields */ }
Expand description

Parse metadata contained in +* files in a package archive.

§Examples

use flate2::read::GzDecoder;
use pkgsrc::{Metadata,MetadataEntry};
use std::fs::File;
use std::io::Read;
use tar::Archive;

fn main() -> Result<(), std::io::Error> {
    let pkg = File::open("package-1.0.tgz")?;
    let mut archive = Archive::new(GzDecoder::new(pkg));
    let mut metadata = Metadata::new();

    for file in archive.entries()? {
        let mut file = file?;
        let fname = String::from(file.header().path()?.to_str().unwrap());
        let mut s = String::new();

        if let Some(entry) = MetadataEntry::from_filename(fname.as_str()) {
            file.read_to_string(&mut s)?;
            if let Err(e) = metadata.read_metadata(entry, &s) {
                panic!("Bad metadata: {}", e);
            }
        }
    }

    if let Err(e) = metadata.is_valid() {
        panic!("Bad metadata: {}", e);
    }

    println!("Information for package-1.0");
    println!("Comment: {}", metadata.comment());
    println!("Files:");
    for line in metadata.contents().lines() {
        if !line.starts_with('@') && !line.starts_with('+') {
            println!("{}", line);
        }
    }

    Ok(())
}

Implementations§

source§

impl Metadata

source

pub fn new() -> Metadata

Return a new empty Metadata container.

source

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

Return the optional +BUILD_INFO file as a vector of strings.

source

pub fn build_version(&self) -> &Option<Vec<String>>

Return the optional +BUILD_VERSION file as a vector of strings.

source

pub fn comment(&self) -> &String

Return the mandatory +COMMENT file as a string. This should be a single line.

source

pub fn contents(&self) -> &String

Return the mandatory +CONTENTS (i.e. packlist or PLIST) file as a complete string.

source

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

Return the optional +DEINSTALL script as complete string.

source

pub fn desc(&self) -> &String

Return the mandatory +DESC file as a complete string.

source

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

Return the optional +DISPLAY (i.e. MESSAGE) file as a complete string.

source

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

Return the optional +INSTALL script as a complete string.

source

pub fn installed_info(&self) -> &Option<Vec<String>>

Return the optional +INSTALLED_INFO file as a vector of strings.

source

pub fn mtree_dirs(&self) -> &Option<Vec<String>>

Return the optional +MTREE_DIRS file (obsolete) as a vector of strings.

source

pub fn preserve(&self) -> &Option<Vec<String>>

Return the optional +PRESERVE file as a vector of strings.

source

pub fn required_by(&self) -> &Option<Vec<String>>

Return the optional +REQUIRED_BY file as a vector of strings.

source

pub fn size_all(&self) -> &Option<i64>

Return the optional +SIZE_ALL file as an i64.

source

pub fn size_pkg(&self) -> &Option<i64>

Return the optional +SIZE_PKG file as an i64.

source

pub fn read_metadata( &mut self, entry: MetadataEntry, value: &str, ) -> Result<(), &'static str>

Read in a metadata file fname and its value as strings, populating the associated Metadata struct.

§Example
use pkgsrc::{Metadata, MetadataEntry};

let mut m = Metadata::new();
m.read_metadata(MetadataEntry::Comment, "This is a package comment");
source

pub fn is_valid(&self) -> Result<(), &'static str>

Ensure the required files (+COMMENT, +CONTENTS, and +DESC) have been registered, indicating that this is a valid package.

Trait Implementations§

source§

impl Debug for Metadata

source§

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

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

impl Default for Metadata

source§

fn default() -> Metadata

Returns the “default value” for a type. Read more

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.