[−][src]Struct pkgsrc::Metadata
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(()) }
Methods
impl Metadata[src]
pub fn new() -> Metadata[src]
Return a new empty Metadata container.
pub fn build_info(&self) -> &Option<Vec<String>>[src]
Return the optional +BUILD_INFO file as a vector of strings.
pub fn build_version(&self) -> &Option<Vec<String>>[src]
Return the optional +BUILD_VERSION file as a vector of strings.
pub fn comment(&self) -> &String[src]
Return the mandatory +COMMENT file as a string. This should be a
single line.
pub fn contents(&self) -> &String[src]
Return the mandatory +CONTENTS (i.e. packlist or PLIST) file as a
complete string.
pub fn deinstall(&self) -> &Option<String>[src]
Return the optional +DEINSTALL script as complete string.
pub fn desc(&self) -> &String[src]
Return the mandatory +DESC file as a complete string.
pub fn display(&self) -> &Option<String>[src]
Return the optional +DISPLAY (i.e. MESSAGE) file as a complete string.
pub fn install(&self) -> &Option<String>[src]
Return the optional +INSTALL script as a complete string.
pub fn installed_info(&self) -> &Option<Vec<String>>[src]
Return the optional +INSTALLED_INFO file as a vector of strings.
pub fn mtree_dirs(&self) -> &Option<Vec<String>>[src]
Return the optional +MTREE_DIRS file (obsolete) as a vector of strings.
pub fn preserve(&self) -> &Option<Vec<String>>[src]
Return the optional +PRESERVE file as a vector of strings.
pub fn required_by(&self) -> &Option<Vec<String>>[src]
Return the optional +REQUIRED_BY file as a vector of strings.
pub fn size_all(&self) -> &Option<i64>[src]
Return the optional +SIZE_ALL file as an i64.
pub fn size_pkg(&self) -> &Option<i64>[src]
Return the optional +SIZE_PKG file as an i64.
pub fn read_metadata(
&mut self,
entry: MetadataEntry,
value: &str
) -> Result<(), &'static str>[src]
&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");
pub fn is_valid(&self) -> Result<(), &'static str>[src]
Ensure the required files (+COMMENT, +CONTENTS, and +DESC) have
been registered, indicating that this is a valid package.
Trait Implementations
Auto Trait Implementations
impl Send for Metadata
impl Unpin for Metadata
impl Sync for Metadata
impl RefUnwindSafe for Metadata
impl UnwindSafe for Metadata
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> From<T> for T[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,