pub enum Mtree {
V1(Vec<Path>),
V2(Vec<Path>),
}Expand description
A representation of the ALPM-MTREE file format.
Tracks all available versions of the file format.
Variants§
Implementations§
Source§impl Mtree
impl Mtree
Sourcepub fn validate_paths(
&self,
input_paths: &InputPaths<'_, '_>,
) -> Result<(), Error>
pub fn validate_paths( &self, input_paths: &InputPaths<'_, '_>, ) -> Result<(), Error>
Validates an InputPaths.
With input_pathsa set of relative paths and a common base directory is provided.
Each member of InputPaths::paths is compared with the data available in self by
retrieving metadata from the on-disk files below InputPaths::base_dir.
For this, MTREE_PATH_PREFIX is stripped from each Path
tracked by the Mtree and afterwards each Path is
compared with the respective file in InputPaths::base_dir.
This includes checking if
- each relative path in
InputPaths::pathsmatches a record in the ALPM-MTREE data, - each relative path in
InputPaths::pathsrelates to an existing file, directory or symlink inInputPaths::base_dir, - the target of each symlink in the ALPM-MTREE data matches that of the corresponding on-disk file,
- size and SHA-256 hash digest of each file in the ALPM-MTREE data matches that of the corresponding on-disk file,
- the ALPM-MTREE data file itself is included in the ALPM-MTREE data,
- and the creation time, UID, GID and file mode of each file in the ALPM-MTREE data matches that of the corresponding on-disk file.
§Errors
Returns an error if
InputPaths::pathscontains duplicates,- or one of the ALPM-MTREE data entries
- does not have a matching on-disk file, directory or symlink (depending on type),
- has a mismatching symlink target from that of a corresponding on-disk file,
- has a mismatching size or SHA-256 hash digest from that of a corresponding on-disk file,
- is the ALPM-MTREE file,
- or has a mismatching creation time, UID, GID or file mode from that of a corresponding on-disk file,
- or one of the file system paths in
InputPaths::pathshas no matching ALPM-MTREE entry.
Trait Implementations§
Source§impl FromStr for Mtree
impl FromStr for Mtree
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