pub enum MtreeSchema {
V1(SchemaVersion),
V2(SchemaVersion),
}Expand description
An enum tracking all available ALPM-MTREE schemas.
The schema of an ALPM-MTREE refers to its available fields in a specific version.
Variants§
Trait Implementations§
Source§impl AsRef<SchemaVersion> for MtreeSchema
impl AsRef<SchemaVersion> for MtreeSchema
Source§fn as_ref(&self) -> &SchemaVersion
fn as_ref(&self) -> &SchemaVersion
Returns a reference to the targeted SchemaVersion.
Source§impl Clone for MtreeSchema
impl Clone for MtreeSchema
Source§impl Debug for MtreeSchema
impl Debug for MtreeSchema
Source§impl Default for MtreeSchema
impl Default for MtreeSchema
Source§fn default() -> Self
fn default() -> Self
Returns the default MtreeSchema variant (MtreeSchema::V2).
Source§impl Display for MtreeSchema
impl Display for MtreeSchema
impl Eq for MtreeSchema
Source§impl FileFormatSchema for MtreeSchema
impl FileFormatSchema for MtreeSchema
Source§fn derive_from_file(file: impl AsRef<Path>) -> Result<Self, Error>where
Self: Sized,
fn derive_from_file(file: impl AsRef<Path>) -> Result<Self, Error>where
Self: Sized,
Derives an MtreeSchema from an ALPM-MTREE file.
Opens the file and defers to MtreeSchema::derive_from_reader.
§Errors
Returns an error if
- opening
filefor reading fails - or deriving a
MtreeSchemafrom the contents offilefails.
Source§fn derive_from_reader(reader: impl Read) -> Result<Self, Error>where
Self: Sized,
fn derive_from_reader(reader: impl Read) -> Result<Self, Error>where
Self: Sized,
Derives an MtreeSchema from ALPM-MTREE data in a reader.
Reads the reader to string and defers to MtreeSchema::derive_from_str.
§Errors
Returns an error if
- reading a
Stringfromreaderfails - or deriving a
MtreeSchemafrom the contents ofreaderfails.
Source§fn derive_from_str(s: &str) -> Result<MtreeSchema, Error>
fn derive_from_str(s: &str) -> Result<MtreeSchema, Error>
Derives an MtreeSchema from a string slice containing ALPM-MTREE data.
Since the ALPM-MTREE format does not carry any version information, this function checks
whether s contains md5= or md5digest=.
If it does, the input is considered to be ALPM-MTREEv1.
If the strings are not found, ALPM-MTREEv2 is assumed.
§Examples
use alpm_common::FileFormatSchema;
use alpm_mtree::MtreeSchema;
use alpm_types::{SchemaVersion, semver_version::Version};
let mtree_v2 = r#"
#mtree
/set mode=644 uid=0 gid=0 type=file
./some_file time=1700000000.0 size=1337 sha256digest=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
./some_link type=link link=some_file time=1700000000.0
./some_dir type=dir time=1700000000.0
"#;
assert_eq!(
MtreeSchema::V2(SchemaVersion::new(Version::new(2, 0, 0))),
MtreeSchema::derive_from_str(mtree_v2)?
);
let mtree_v1 = r#"
#mtree
/set mode=644 uid=0 gid=0 type=file
./some_file time=1700000000.0 size=1337 sha256digest=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef md5digest=d3b07384d113edec49eaa6238ad5ff00
./some_link type=link link=some_file time=1700000000.0
./some_dir type=dir time=1700000000.0
"#;
assert_eq!(
MtreeSchema::V1(SchemaVersion::new(Version::new(1, 0, 0))),
MtreeSchema::derive_from_str(mtree_v1)?
);§Errors
Returns an error if
- the first
xdatakeyword is assigned an empty string, - or the first
xdatakeyword does not assign “pkgtype”.
Source§impl From<BsdtarOptions> for MtreeSchema
impl From<BsdtarOptions> for MtreeSchema
Source§fn from(value: BsdtarOptions) -> Self
fn from(value: BsdtarOptions) -> Self
Creates an MtreeSchema from a BsdtarOptions
Source§impl FromStr for MtreeSchema
impl FromStr for MtreeSchema
Source§fn from_str(s: &str) -> Result<MtreeSchema, Self::Err>
fn from_str(s: &str) -> Result<MtreeSchema, Self::Err>
Creates an MtreeSchema from string slice s.
Relies on SchemaVersion::from_str to create a corresponding MtreeSchema from
s.
§Errors
Returns an error if
- no
SchemaVersioncan be created froms, - or the conversion from
SchemaVersiontoMtreeSchemafails.
Source§impl MetadataFile<MtreeSchema> for Mtree
impl MetadataFile<MtreeSchema> for Mtree
Source§fn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<MtreeSchema>,
) -> Result<Self, Error>
fn from_file_with_schema( file: impl AsRef<Path>, schema: Option<MtreeSchema>, ) -> Result<Self, Error>
Creates a Mtree from file, optionally validated using a MtreeSchema.
Opens the file and defers to Mtree::from_reader_with_schema.
§Note
To automatically derive the MtreeSchema, use Mtree::from_file.
§Examples
use std::{fs::File, io::Write};
use alpm_common::{FileFormatSchema, MetadataFile};
use alpm_mtree::{Mtree, MtreeSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
// Prepare a file with ALPM-MTREE data
let file = {
let mtree_data = r#"#mtree
/set mode=644 uid=0 gid=0 type=file
./some_file time=1700000000.0 size=1337 sha256digest=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
./some_link type=link link=some_file time=1700000000.0
./some_dir type=dir time=1700000000.0
"#;
let mtree_file = tempfile::NamedTempFile::new()?;
let mut output = File::create(&mtree_file)?;
write!(output, "{}", mtree_data)?;
mtree_file
};
let mtree = Mtree::from_file_with_schema(
file.path().to_path_buf(),
Some(MtreeSchema::V2(SchemaVersion::new(Version::new(2, 0, 0)))),
)?;§Errors
Returns an error if
- the
filecannot be opened for reading, - no variant of
Mtreecan be constructed from the contents offile, - or
schemaisSomeand theMtreeSchemadoes not match the contents offile.
Source§fn from_reader_with_schema(
reader: impl Read,
schema: Option<MtreeSchema>,
) -> Result<Self, Error>
fn from_reader_with_schema( reader: impl Read, schema: Option<MtreeSchema>, ) -> Result<Self, Error>
Creates a Mtree from a reader, optionally validated using a
MtreeSchema.
Reads the reader to string (and decompresses potentially gzip compressed data on-the-fly).
Then defers to Mtree::from_str_with_schema.
§Note
To automatically derive the MtreeSchema, use Mtree::from_reader.
§Examples
use std::{fs::File, io::Write};
use alpm_common::MetadataFile;
use alpm_mtree::{Mtree, MtreeSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
// Prepare a reader with ALPM-MTREE data
let reader = {
let mtree_data = r#"#mtree
/set mode=644 uid=0 gid=0 type=file
./some_file time=1700000000.0 size=1337 sha256digest=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
./some_link type=link link=some_file time=1700000000.0
./some_dir type=dir time=1700000000.0
"#;
let mtree_file = tempfile::NamedTempFile::new()?;
let mut output = File::create(&mtree_file)?;
write!(output, "{}", mtree_data)?;
File::open(&mtree_file.path())?
};
let mtree = Mtree::from_reader_with_schema(
reader,
Some(MtreeSchema::V2(SchemaVersion::new(Version::new(2, 0, 0)))),
)?;§Errors
Returns an error if
- the
readercannot be read to string, - no variant of
Mtreecan be constructed from the contents of thereader, - or
schemaisSomeand theMtreeSchemadoes not match the contents of thereader.
Source§fn from_str_with_schema(
s: &str,
schema: Option<MtreeSchema>,
) -> Result<Self, Error>
fn from_str_with_schema( s: &str, schema: Option<MtreeSchema>, ) -> Result<Self, Error>
Creates a Mtree from string slice, optionally validated using a
MtreeSchema.
If schema is None attempts to detect the MtreeSchema from s.
Attempts to create a Mtree variant that corresponds to the MtreeSchema.
§Note
To automatically derive the MtreeSchema, use Mtree::from_str.
§Examples
use std::{fs::File, io::Write};
use alpm_common::MetadataFile;
use alpm_mtree::{Mtree, MtreeSchema};
use alpm_types::{SchemaVersion, semver_version::Version};
let mtree_v2 = r#"
#mtree
/set mode=644 uid=0 gid=0 type=file
./some_file time=1700000000.0 size=1337 sha256digest=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
./some_link type=link link=some_file time=1700000000.0
./some_dir type=dir time=1700000000.0
"#;
let mtree = Mtree::from_str_with_schema(
mtree_v2,
Some(MtreeSchema::V2(SchemaVersion::new(Version::new(2, 0, 0)))),
)?;
let mtree_v1 = r#"
#mtree
/set mode=644 uid=0 gid=0 type=file
./some_file time=1700000000.0 size=1337 sha256digest=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef md5digest=d3b07384d113edec49eaa6238ad5ff00
./some_link type=link link=some_file time=1700000000.0
./some_dir type=dir time=1700000000.0
"#;
let mtree = Mtree::from_str_with_schema(
mtree_v1,
Some(MtreeSchema::V1(SchemaVersion::new(Version::new(1, 0, 0)))),
)?;§Errors
Returns an error if
schemaisSomeand the specified variant ofMtreecannot be constructed froms,schemaisNoneand- a
MtreeSchemacannot be derived froms, - or the detected variant of
Mtreecannot be constructed froms.
- a
Source§impl MetadataFile<MtreeSchema> for MtreeTransfer
impl MetadataFile<MtreeSchema> for MtreeTransfer
Source§fn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<MtreeSchema>,
) -> Result<Self, Self::Err>where
Self: Sized,
fn from_file_with_schema(
file: impl AsRef<Path>,
schema: Option<MtreeSchema>,
) -> Result<Self, Self::Err>where
Self: Sized,
Source§fn from_reader_with_schema(
reader: impl Read,
schema: Option<MtreeSchema>,
) -> Result<Self, Self::Err>where
Self: Sized,
fn from_reader_with_schema(
reader: impl Read,
schema: Option<MtreeSchema>,
) -> Result<Self, Self::Err>where
Self: Sized,
Source§fn from_str_with_schema(
s: &str,
schema: Option<MtreeSchema>,
) -> Result<Self, Self::Err>where
Self: Sized,
fn from_str_with_schema(
s: &str,
schema: Option<MtreeSchema>,
) -> Result<Self, Self::Err>where
Self: Sized,
Source§impl PartialEq for MtreeSchema
impl PartialEq for MtreeSchema
impl StructuralPartialEq for MtreeSchema
Source§impl TryFrom<SchemaVersion> for MtreeSchema
impl TryFrom<SchemaVersion> for MtreeSchema
Source§fn try_from(value: SchemaVersion) -> Result<Self, Self::Error>
fn try_from(value: SchemaVersion) -> Result<Self, Self::Error>
Converts a SchemaVersion to an MtreeSchema.
§Errors
Returns an error if the SchemaVersion’s inner Version does not provide a major
version that corresponds to an MtreeSchema variant.