Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make methods working with filesystem optional #310

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.toml
Expand Up @@ -18,8 +18,9 @@ writers. Additionally, great lengths are taken to ensure that the entire
contents are never required to be entirely resident in memory all at once.
"""


[dependencies]
filetime = "0.2.8"
filetime = { version = "0.2.8", optional = true }

[dev-dependencies]
tempfile = "3"
Expand All @@ -30,3 +31,4 @@ libc = "0.2"

[features]
default = ["xattr"]
fs = ["filetime"]
2 changes: 2 additions & 0 deletions src/archive.rs
Expand Up @@ -103,6 +103,7 @@ impl<R: Read> Archive<R> {
/// let mut ar = Archive::new(File::open("foo.tar").unwrap());
/// ar.unpack("foo").unwrap();
/// ```
#[cfg(feature = "fs")]
pub fn unpack<P: AsRef<Path>>(&mut self, dst: P) -> io::Result<()> {
let me: &mut Archive<dyn Read> = self;
me._unpack(dst.as_ref())
Expand Down Expand Up @@ -197,6 +198,7 @@ impl Archive<dyn Read + '_> {
})
}

#[cfg(feature = "fs")]
fn _unpack(&mut self, dst: &Path) -> io::Result<()> {
if dst.symlink_metadata().is_err() {
fs::create_dir_all(&dst)
Expand Down
5 changes: 5 additions & 0 deletions src/entry.rs
Expand Up @@ -7,6 +7,7 @@ use std::io::{self, Error, ErrorKind, SeekFrom};
use std::marker;
use std::path::{Component, Path, PathBuf};

#[cfg(feature = "fs")]
use filetime::{self, FileTime};

use crate::archive::ArchiveInner;
Expand Down Expand Up @@ -199,6 +200,7 @@ impl<'a, R: Read> Entry<'a, R> {
/// file.unpack(format!("file-{}", i)).unwrap();
/// }
/// ```
#[cfg(feature = "fs")]
pub fn unpack<P: AsRef<Path>>(&mut self, dst: P) -> io::Result<Unpacked> {
self.fields.unpack(None, dst.as_ref())
}
Expand Down Expand Up @@ -227,6 +229,7 @@ impl<'a, R: Read> Entry<'a, R> {
/// file.unpack_in("target").unwrap();
/// }
/// ```
#[cfg(feature = "fs")]
pub fn unpack_in<P: AsRef<Path>>(&mut self, dst: P) -> io::Result<bool> {
self.fields.unpack_in(dst.as_ref())
}
Expand Down Expand Up @@ -363,6 +366,7 @@ impl<'a> EntryFields<'a> {
)))
}

#[cfg(feature = "fs")]
fn unpack_in(&mut self, dst: &Path) -> io::Result<bool> {
// Notes regarding bsdtar 2.8.3 / libarchive 2.8.3:
// * Leading '/'s are trimmed. For example, `///test` is treated as
Expand Down Expand Up @@ -443,6 +447,7 @@ impl<'a> EntryFields<'a> {
})
}

#[cfg(feature = "fs")]
/// Returns access to the header of this entry in the archive.
fn unpack(&mut self, target_base: Option<&Path>, dst: &Path) -> io::Result<Unpacked> {
fn set_perms_ownerships(
Expand Down