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");