ArchiveMatch

Struct ArchiveMatch 

Source
pub struct ArchiveMatch { /* private fields */ }
Expand description

Archive matcher for filtering entries based on patterns

§Thread Safety

ArchiveMatch is Send but not Sync. You can transfer ownership between threads, but cannot share references across threads.

Implementations§

Source§

impl ArchiveMatch

Source

pub fn new() -> Result<Self>

Create a new archive matcher

Source

pub fn include_pattern(&mut self, pattern: &str) -> Result<()>

Include entries matching a shell-style pattern

Patterns may contain wildcards:

  • * matches any sequence of characters
  • ? matches any single character
  • [...] matches any character in the brackets
§Examples
use libarchive2::ArchiveMatch;

let mut matcher = ArchiveMatch::new()?;
matcher.include_pattern("*.txt")?;  // Include all .txt files
matcher.include_pattern("docs/*")?;  // Include all files in docs/
Source

pub fn exclude_pattern(&mut self, pattern: &str) -> Result<()>

Exclude entries matching a shell-style pattern

§Examples
use libarchive2::ArchiveMatch;

let mut matcher = ArchiveMatch::new()?;
matcher.exclude_pattern("*.o")?;     // Exclude object files
matcher.exclude_pattern("*.tmp")?;   // Exclude temp files
Source

pub fn include_pathname(&mut self, pathname: &str) -> Result<()>

Include entries matching a specific pathname

This is for exact pathname matches, not patterns.

§Examples
use libarchive2::ArchiveMatch;

let mut matcher = ArchiveMatch::new()?;
matcher.include_pathname("README.md")?;
matcher.include_pathname("src/main.rs")?;
Source

pub fn exclude_pathname(&mut self, _pathname: &str) -> Result<()>

Exclude entries matching a specific pathname

Note: This method is not yet fully implemented. Use exclude_pattern() for pattern-based exclusions instead.

§Examples
use libarchive2::ArchiveMatch;

let mut matcher = ArchiveMatch::new()?;
// Use exclude_pattern instead:
matcher.exclude_pattern(".DS_Store")?;
matcher.exclude_pattern("thumbs.db")?;
Source

pub fn include_time_newer_than(&mut self, sec: i64, nsec: i64) -> Result<()>

Include only entries newer than the specified time (in seconds since epoch)

§Examples
use libarchive2::ArchiveMatch;
use std::time::{SystemTime, UNIX_EPOCH};

let mut matcher = ArchiveMatch::new()?;
let one_week_ago = SystemTime::now()
    .duration_since(UNIX_EPOCH)?
    .as_secs() as i64 - (7 * 24 * 60 * 60);
matcher.include_time_newer_than(one_week_ago, 0)?;
Source

pub fn include_time_older_than(&mut self, sec: i64, nsec: i64) -> Result<()>

Include only entries older than the specified time (in seconds since epoch)

§Examples
use libarchive2::ArchiveMatch;
use std::time::{SystemTime, UNIX_EPOCH};

let mut matcher = ArchiveMatch::new()?;
let one_year_ago = SystemTime::now()
    .duration_since(UNIX_EPOCH)?
    .as_secs() as i64 - (365 * 24 * 60 * 60);
matcher.include_time_older_than(one_year_ago, 0)?;
Source

pub fn include_uid(&mut self, uid: i64) -> Result<()>

Include only entries with owner matching the specified UID

§Examples
use libarchive2::ArchiveMatch;

let mut matcher = ArchiveMatch::new()?;
matcher.include_uid(1000)?;  // Include only files owned by UID 1000
Source

pub fn include_gid(&mut self, gid: i64) -> Result<()>

Include only entries with group matching the specified GID

§Examples
use libarchive2::ArchiveMatch;

let mut matcher = ArchiveMatch::new()?;
matcher.include_gid(1000)?;  // Include only files owned by GID 1000
Source

pub fn exclude_uid(&mut self, _uid: i64) -> Result<()>

Exclude entries with owner matching the specified UID

Note: This method is not yet implemented as libarchive doesn’t provide a direct API for excluding UIDs. Use custom filtering in your application code.

Source

pub fn exclude_gid(&mut self, _gid: i64) -> Result<()>

Exclude entries with group matching the specified GID

Note: This method is not yet implemented as libarchive doesn’t provide a direct API for excluding GIDs. Use custom filtering in your application code.

Source

pub fn matches(&mut self, entry: &Entry<'_>) -> Result<bool>

Check if an entry matches the configured filters

Returns true if the entry should be included based on the configured patterns.

§Examples
use libarchive2::{ReadArchive, ArchiveMatch};

let mut archive = ReadArchive::open("archive.tar.gz")?;
let mut matcher = ArchiveMatch::new()?;
matcher.include_pattern("*.txt")?;

while let Some(entry) = archive.next_entry()? {
    if matcher.matches(&entry)? {
        println!("Matched: {}", entry.pathname().unwrap_or_default());
    }
}
Source

pub fn time_excluded(&mut self, entry: &Entry<'_>) -> Result<bool>

Check if an entry is time-excluded based on the configured time filters

Source

pub fn path_excluded(&mut self, entry: &Entry<'_>) -> Result<bool>

Check if an entry’s path is excluded based on the configured patterns

Trait Implementations§

Source§

impl Drop for ArchiveMatch

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for ArchiveMatch

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.