pub enum RepoDescFile {
V1(RepoDescFileV1),
V2(RepoDescFileV2),
}Expand description
A representation of the alpm-repo-desc file format.
Tracks all supported schema versions (v1 and v2) of the package repository description file.
Each variant corresponds to a distinct layout of the format.
Variants§
V1(RepoDescFileV1)
The alpm-repo-descv1 file format.
V2(RepoDescFileV2)
The alpm-repo-descv2 file format.
This revision of the file format, removes %MD5SUM% and makes the %PGPSIG% section optional.
Trait Implementations§
Source§impl Clone for RepoDescFile
impl Clone for RepoDescFile
Source§fn clone(&self) -> RepoDescFile
fn clone(&self) -> RepoDescFile
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RepoDescFile
impl Debug for RepoDescFile
Source§impl Display for RepoDescFile
impl Display for RepoDescFile
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Returns the textual representation of the RepoDescFile in its corresponding
alpm-repo-desc format.
Source§impl FromStr for RepoDescFile
impl FromStr for RepoDescFile
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Creates a RepoDescFile from a string slice.
Internally calls RepoDescFile::from_str_with_schema with schema set to None.
§Errors
Returns an error if RepoDescFile::from_str_with_schema fails.
Source§impl MetadataFile<RepoDescSchema> for RepoDescFile
impl MetadataFile<RepoDescSchema> for RepoDescFile
Source§fn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<RepoDescSchema>,
) -> Result<Self, Error>
fn from_file_with_schema( file: impl AsRef<Path>, schema: Option<RepoDescSchema>, ) -> Result<Self, Error>
Creates a RepoDescFile from a file on disk, optionally validated using a
RepoDescSchema.
Opens the file and defers to RepoDescFile::from_reader_with_schema.
§Examples
use std::{fs::File, io::Write};
use alpm_common::{FileFormatSchema, MetadataFile};
use alpm_repo_db::desc::{RepoDescFile, RepoDescSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
// Prepare a file with package repository desc data (v1)
let (file, desc_data) = {
let desc_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst
%NAME%
example-meta
%BASE%
example-meta
%VERSION%
1.0.0-1
%DESC%
An example meta package
%CSIZE%
4634
%ISIZE%
0
%MD5SUM%
d3b07384d113edec49eaa6238ad5ff00
%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
%PGPSIG%
iHUEABYKAB0WIQRizHP4hOUpV7L92IObeih9mi7GCAUCaBZuVAAKCRCbeih9mi7GCIlMAP9ws/jU4f580ZRQlTQKvUiLbAZOdcB7mQQj83hD1Nc/GwD/WIHhO1/OQkpMERejUrLo3AgVmY3b4/uGhx9XufWEbgE=
%URL%
https://example.org/
%LICENSE%
GPL-3.0-or-later
%ARCH%
any
%BUILDDATE%
1729181726
%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>
"#;
let file = tempfile::NamedTempFile::new()?;
let mut output = File::create(&file)?;
write!(output, "{}", desc_data)?;
(file, desc_data)
};
let repo_desc = RepoDescFile::from_file_with_schema(
file.path(),
Some(RepoDescSchema::V1(SchemaVersion::new(Version::new(
1, 0, 0,
)))),
)?;
assert_eq!(repo_desc.to_string(), desc_data);§Errors
Returns an error if:
- the file cannot be opened for reading,
- the contents cannot be parsed into any known
RepoDescFilevariant, - or the provided
RepoDescSchemadoes not match the contents of the file.
Source§fn from_reader_with_schema(
reader: impl Read,
schema: Option<RepoDescSchema>,
) -> Result<Self, Error>
fn from_reader_with_schema( reader: impl Read, schema: Option<RepoDescSchema>, ) -> Result<Self, Error>
Creates a RepoDescFile from any readable stream, optionally validated using a
RepoDescSchema.
Reads the reader to a string buffer and defers to RepoDescFile::from_str_with_schema.
§Examples
use std::{fs::File, io::Write};
use alpm_common::MetadataFile;
use alpm_repo_db::desc::{RepoDescFile, RepoDescSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
// Prepare a reader with package repository desc data (v2)
let (reader, desc_data) = {
let desc_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst
%NAME%
example-meta
%BASE%
example-meta
%VERSION%
1.0.0-1
%DESC%
An example meta package
%CSIZE%
4634
%ISIZE%
0
%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
%URL%
https://example.org/
%LICENSE%
GPL-3.0-or-later
%ARCH%
any
%BUILDDATE%
1729181726
%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>
"#;
let file = tempfile::NamedTempFile::new()?;
let mut output = File::create(&file)?;
write!(output, "{}", desc_data)?;
(File::open(&file.path())?, desc_data)
};
let repo_desc = RepoDescFile::from_reader_with_schema(
reader,
Some(RepoDescSchema::V2(SchemaVersion::new(Version::new(
2, 0, 0,
)))),
)?;
assert_eq!(repo_desc.to_string(), desc_data);§Errors
Returns an error if:
- the
readercannot be read to string, - the data cannot be parsed into a known
RepoDescFilevariant, - or the provided
RepoDescSchemadoes not match the parsed content.
Source§fn from_str_with_schema(
s: &str,
schema: Option<RepoDescSchema>,
) -> Result<Self, Error>
fn from_str_with_schema( s: &str, schema: Option<RepoDescSchema>, ) -> Result<Self, Error>
Creates a RepoDescFile from a string slice, optionally validated using a
RepoDescSchema.
If schema is None, automatically infers the schema version by inspecting the input
(v1 if %MD5SUM% is present, v2 otherwise).
§Examples
use alpm_common::MetadataFile;
use alpm_repo_db::desc::{RepoDescFile, RepoDescSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
let v1_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst
%NAME%
example-meta
%BASE%
example-meta
%VERSION%
1.0.0-1
%DESC%
An example meta package
%CSIZE%
4634
%ISIZE%
0
%MD5SUM%
d3b07384d113edec49eaa6238ad5ff00
%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
%PGPSIG%
iHUEABYKAB0WIQRizHP4hOUpV7L92IObeih9mi7GCAUCaBZuVAAKCRCbeih9mi7GCIlMAP9ws/jU4f580ZRQlTQKvUiLbAZOdcB7mQQj83hD1Nc/GwD/WIHhO1/OQkpMERejUrLo3AgVmY3b4/uGhx9XufWEbgE=
%URL%
https://example.org/
%LICENSE%
GPL-3.0-or-later
%ARCH%
any
%BUILDDATE%
1729181726
%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>
"#;
let repo_desc_v1 = RepoDescFile::from_str_with_schema(
v1_data,
Some(RepoDescSchema::V1(SchemaVersion::new(Version::new(
1, 0, 0,
)))),
)?;
assert_eq!(repo_desc_v1.to_string(), v1_data);
let v2_data = r#"%FILENAME%
example-meta-1.0.0-1-any.pkg.tar.zst
%NAME%
example-meta
%BASE%
example-meta
%VERSION%
1.0.0-1
%DESC%
An example meta package
%CSIZE%
4634
%ISIZE%
0
%SHA256SUM%
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
%URL%
https://example.org/
%LICENSE%
GPL-3.0-or-later
%ARCH%
any
%BUILDDATE%
1729181726
%PACKAGER%
Foobar McFooface <foobar@mcfooface.org>
"#;
let repo_desc_v2 = RepoDescFile::from_str_with_schema(
v2_data,
Some(RepoDescSchema::V2(SchemaVersion::new(Version::new(
2, 0, 0,
)))),
)?;
assert_eq!(repo_desc_v2.to_string(), v2_data);§Errors
Returns an error if:
- the input cannot be parsed into a valid
RepoDescFile, - or the derived or provided schema does not match the detected format.