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
impl Metadata
Sourcepub fn build_info(&self) -> &Option<Vec<String>>
pub fn build_info(&self) -> &Option<Vec<String>>
Return the optional +BUILD_INFO file as a vector of strings.
Sourcepub fn build_version(&self) -> &Option<Vec<String>>
pub fn build_version(&self) -> &Option<Vec<String>>
Return the optional +BUILD_VERSION file as a vector of strings.
Sourcepub fn comment(&self) -> &String
pub fn comment(&self) -> &String
Return the mandatory +COMMENT file as a string. This should be a
single line.
Sourcepub fn contents(&self) -> &String
pub fn contents(&self) -> &String
Return the mandatory +CONTENTS (i.e. packlist or PLIST) file as a
complete string.
Sourcepub fn deinstall(&self) -> &Option<String>
pub fn deinstall(&self) -> &Option<String>
Return the optional +DEINSTALL script as complete string.
Sourcepub fn display(&self) -> &Option<String>
pub fn display(&self) -> &Option<String>
Return the optional +DISPLAY (i.e. MESSAGE) file as a complete string.
Sourcepub fn install(&self) -> &Option<String>
pub fn install(&self) -> &Option<String>
Return the optional +INSTALL script as a complete string.
Sourcepub fn installed_info(&self) -> &Option<Vec<String>>
pub fn installed_info(&self) -> &Option<Vec<String>>
Return the optional +INSTALLED_INFO file as a vector of strings.
Sourcepub fn mtree_dirs(&self) -> &Option<Vec<String>>
pub fn mtree_dirs(&self) -> &Option<Vec<String>>
Return the optional +MTREE_DIRS file (obsolete) as a vector of strings.
Sourcepub fn preserve(&self) -> &Option<Vec<String>>
pub fn preserve(&self) -> &Option<Vec<String>>
Return the optional +PRESERVE file as a vector of strings.
Sourcepub fn required_by(&self) -> &Option<Vec<String>>
pub fn required_by(&self) -> &Option<Vec<String>>
Return the optional +REQUIRED_BY file as a vector of strings.
Sourcepub fn read_metadata(
&mut self,
entry: MetadataEntry,
value: &str,
) -> Result<(), &'static str>
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");Trait Implementations§
impl Eq for Metadata
impl StructuralPartialEq for Metadata
Auto Trait Implementations§
impl Freeze for Metadata
impl RefUnwindSafe for Metadata
impl Send for Metadata
impl Sync for Metadata
impl Unpin for Metadata
impl UnwindSafe for Metadata
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.