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
impl ArchiveMatch
Sourcepub fn include_pattern(&mut self, pattern: &str) -> Result<()>
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/Sourcepub fn exclude_pattern(&mut self, pattern: &str) -> Result<()>
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 filesSourcepub fn include_pathname(&mut self, pathname: &str) -> Result<()>
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")?;Sourcepub fn exclude_pathname(&mut self, _pathname: &str) -> Result<()>
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")?;Sourcepub fn include_time_newer_than(&mut self, sec: i64, nsec: i64) -> Result<()>
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)?;Sourcepub fn include_time_older_than(&mut self, sec: i64, nsec: i64) -> Result<()>
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)?;Sourcepub fn include_uid(&mut self, uid: i64) -> Result<()>
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 1000Sourcepub fn include_gid(&mut self, gid: i64) -> Result<()>
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 1000Sourcepub fn exclude_uid(&mut self, _uid: i64) -> Result<()>
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.
Sourcepub fn exclude_gid(&mut self, _gid: i64) -> Result<()>
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.
Sourcepub fn matches(&mut self, entry: &Entry<'_>) -> Result<bool>
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());
}
}Sourcepub fn time_excluded(&mut self, entry: &Entry<'_>) -> Result<bool>
pub fn time_excluded(&mut self, entry: &Entry<'_>) -> Result<bool>
Check if an entry is time-excluded based on the configured time filters
Sourcepub fn path_excluded(&mut self, entry: &Entry<'_>) -> Result<bool>
pub fn path_excluded(&mut self, entry: &Entry<'_>) -> Result<bool>
Check if an entry’s path is excluded based on the configured patterns