From dea0b876406bb774d6beacca19245e1393a3378d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Hornick=C3=BD?= Date: Fri, 27 Jan 2023 14:22:25 +0100 Subject: [PATCH] Make methods working with filesystem optional --- Cargo.toml | 4 +++- src/archive.rs | 2 ++ src/entry.rs | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index bcafdbd7..9411cb6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -30,3 +31,4 @@ libc = "0.2" [features] default = ["xattr"] +fs = ["filetime"] diff --git a/src/archive.rs b/src/archive.rs index e875124a..accfcc68 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -103,6 +103,7 @@ impl Archive { /// let mut ar = Archive::new(File::open("foo.tar").unwrap()); /// ar.unpack("foo").unwrap(); /// ``` + #[cfg(feature = "fs")] pub fn unpack>(&mut self, dst: P) -> io::Result<()> { let me: &mut Archive = self; me._unpack(dst.as_ref()) @@ -197,6 +198,7 @@ impl Archive { }) } + #[cfg(feature = "fs")] fn _unpack(&mut self, dst: &Path) -> io::Result<()> { if dst.symlink_metadata().is_err() { fs::create_dir_all(&dst) diff --git a/src/entry.rs b/src/entry.rs index cce39d45..01492075 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -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; @@ -199,6 +200,7 @@ impl<'a, R: Read> Entry<'a, R> { /// file.unpack(format!("file-{}", i)).unwrap(); /// } /// ``` + #[cfg(feature = "fs")] pub fn unpack>(&mut self, dst: P) -> io::Result { self.fields.unpack(None, dst.as_ref()) } @@ -227,6 +229,7 @@ impl<'a, R: Read> Entry<'a, R> { /// file.unpack_in("target").unwrap(); /// } /// ``` + #[cfg(feature = "fs")] pub fn unpack_in>(&mut self, dst: P) -> io::Result { self.fields.unpack_in(dst.as_ref()) } @@ -363,6 +366,7 @@ impl<'a> EntryFields<'a> { ))) } + #[cfg(feature = "fs")] fn unpack_in(&mut self, dst: &Path) -> io::Result { // Notes regarding bsdtar 2.8.3 / libarchive 2.8.3: // * Leading '/'s are trimmed. For example, `///test` is treated as @@ -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 { fn set_perms_ownerships(