Skip to content

Commit

Permalink
Make the dependency filetime optional
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-morgan committed Jan 7, 2022
1 parent dc78ebe commit 93029ca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -19,7 +19,7 @@ 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 @@ -29,4 +29,4 @@ xattr = { version = "0.2", optional = true }
libc = "0.2"

[features]
default = ["xattr"]
default = ["filetime", "xattr"]
2 changes: 2 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 = "filetime")]
use filetime::{self, FileTime};

use crate::archive::ArchiveInner;
Expand Down Expand Up @@ -617,6 +618,7 @@ impl<'a> EntryFields<'a> {
)
})?;

#[cfg(feature = "filetime")]
if self.preserve_mtime {
if let Ok(mtime) = self.header.mtime() {
// For some more information on this see the comments in
Expand Down
4 changes: 4 additions & 0 deletions tests/all.rs
@@ -1,3 +1,4 @@
#[cfg(feature = "filetime")]
extern crate filetime;
extern crate tar;
extern crate tempfile;
Expand All @@ -10,6 +11,7 @@ use std::io::{self, Cursor};
use std::iter::repeat;
use std::path::{Path, PathBuf};

#[cfg(feature = "filetime")]
use filetime::FileTime;
use tar::{Archive, Builder, Entries, EntryType, Header, HeaderMode};
use tempfile::{Builder as TempBuilder, TempDir};
Expand Down Expand Up @@ -686,6 +688,7 @@ fn empty_filename() {
assert!(ar.unpack(td.path()).is_ok());
}

#[cfg(feature = "filetime")]
#[test]
fn file_times() {
let td = t!(TempBuilder::new().prefix("tar-rs").tempdir());
Expand All @@ -702,6 +705,7 @@ fn file_times() {
assert_eq!(atime.nanoseconds(), 0);
}

#[cfg(feature = "filetime")]
#[test]
fn zero_file_times() {
let td = t!(TempBuilder::new().prefix("tar-rs").tempdir());
Expand Down

0 comments on commit 93029ca

Please sign in to comment.