Metadata

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 Clone for Metadata

Source§

fn clone(&self) -> Metadata

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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
Source§

impl PartialEq for Metadata

Source§

fn eq(&self, other: &Metadata) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Metadata

Source§

impl StructuralPartialEq for Metadata

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.