use std::borrow::Cow;
use std::collections::BTreeMap;
use std::fs::File;
use std::io::{Read, Seek, SeekFrom};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use crate::path::canonical_key;
use crate::time::Timestamp;
use crate::xattr::Xattr;
#[derive(Clone, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub enum FileContent {
Owned(Vec<u8>),
Range(FileRange),
}
impl FileContent {
#[must_use]
pub fn len(&self) -> u64 {
match self {
Self::Owned(bytes) => bytes.len() as u64,
Self::Range(range) => range.len(),
}
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn read(&self) -> std::io::Result<Cow<'_, [u8]>> {
match self {
Self::Owned(bytes) => Ok(Cow::Borrowed(bytes)),
Self::Range(range) => Ok(Cow::Owned(range.read()?)),
}
}
}
impl From<Vec<u8>> for FileContent {
fn from(bytes: Vec<u8>) -> Self {
Self::Owned(bytes)
}
}
impl From<FileRange> for FileContent {
fn from(range: FileRange) -> Self {
Self::Range(range)
}
}
impl From<&[u8]> for FileContent {
fn from(bytes: &[u8]) -> Self {
Self::Owned(bytes.to_vec())
}
}
impl<const N: usize> From<&[u8; N]> for FileContent {
fn from(bytes: &[u8; N]) -> Self {
Self::Owned(bytes.to_vec())
}
}
impl From<&str> for FileContent {
fn from(text: &str) -> Self {
Self::Owned(text.as_bytes().to_vec())
}
}
impl From<String> for FileContent {
fn from(text: String) -> Self {
Self::Owned(text.into_bytes())
}
}
#[derive(Clone)]
pub struct FileRange {
file: Option<Arc<File>>,
path: Arc<PathBuf>,
offset: u64,
len: u64,
}
impl FileRange {
#[must_use]
pub fn new(file: Arc<File>, path: impl Into<PathBuf>, offset: u64, len: u64) -> Self {
Self {
file: Some(file),
path: Arc::new(path.into()),
offset,
len,
}
}
#[must_use]
pub fn at_path(path: impl Into<PathBuf>, offset: u64, len: u64) -> Self {
Self {
file: None,
path: Arc::new(path.into()),
offset,
len,
}
}
#[must_use]
pub fn path(&self) -> &Path {
self.path.as_path()
}
#[must_use]
pub const fn offset(&self) -> u64 {
self.offset
}
#[must_use]
pub const fn len(&self) -> u64 {
self.len
}
#[must_use]
pub const fn is_empty(&self) -> bool {
self.len == 0
}
pub fn read(&self) -> std::io::Result<Vec<u8>> {
let context = |e: std::io::Error| {
std::io::Error::new(
e.kind(),
format!(
"{}: reading {} bytes at offset {}: {e}",
crate::escape::printable_path(&self.path),
self.len,
self.offset
),
)
};
let len = usize::try_from(self.len).map_err(|_| {
std::io::Error::other(format!(
"{}: {} bytes at offset {} is more than this platform addresses",
crate::escape::printable_path(&self.path),
self.len,
self.offset
))
})?;
let mut handle = match &self.file {
Some(file) => file.try_clone().map_err(context)?,
None => open_no_follow(self.path.as_path()).map_err(context)?,
};
handle.seek(SeekFrom::Start(self.offset)).map_err(context)?;
let mut buf = vec![0u8; len];
handle.read_exact(&mut buf).map_err(context)?;
Ok(buf)
}
}
fn open_no_follow(path: &Path) -> std::io::Result<File> {
#[cfg(unix)]
{
use std::os::unix::fs::OpenOptionsExt as _;
std::fs::OpenOptions::new()
.read(true)
.custom_flags(o_nofollow())
.open(path)
}
#[cfg(not(unix))]
{
File::open(path)
}
}
#[cfg(unix)]
const fn o_nofollow() -> i32 {
#[cfg(any(target_os = "linux", target_os = "android"))]
{
if cfg!(any(
target_arch = "arm",
target_arch = "aarch64",
target_arch = "m68k",
target_arch = "powerpc",
target_arch = "powerpc64"
)) {
0o100_000
} else {
0o400_000
}
}
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
{
0o400_000
}
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "dragonfly"
))]
{
0x0100
}
#[cfg(not(any(
target_os = "linux",
target_os = "android",
target_os = "solaris",
target_os = "illumos",
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "dragonfly"
)))]
{
compile_error!(
"no O_NOFOLLOW value is known for this target, and an open that follows a \
symbolic link would read through a name recorded as a link"
);
0
}
}
impl PartialEq for FileRange {
fn eq(&self, other: &Self) -> bool {
self.path == other.path && self.offset == other.offset && self.len == other.len
}
}
impl Eq for FileRange {}
impl std::fmt::Debug for FileRange {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("FileRange")
.field("path", &self.path)
.field("offset", &self.offset)
.field("len", &self.len)
.finish()
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct Metadata {
pub mode: u16,
pub uid: u32,
pub gid: u32,
pub atime: Timestamp,
pub ctime: Timestamp,
pub mtime: Timestamp,
}
#[cfg(any(feature = "ext", feature = "btrfs"))]
pub(crate) const MODE_TYPE_MASK: u16 = 0o170000;
impl Metadata {
#[must_use]
pub fn new(mode: u16, mtime: Timestamp) -> Self {
Self {
mode,
uid: 0,
gid: 0,
atime: mtime,
ctime: mtime,
mtime,
}
}
#[must_use]
pub fn owned_by(mut self, uid: u32, gid: u32) -> Self {
self.uid = uid;
self.gid = gid;
self
}
#[must_use]
pub fn with_times(mut self, atime: Timestamp, ctime: Timestamp, mtime: Timestamp) -> Self {
self.atime = atime;
self.ctime = ctime;
self.mtime = mtime;
self
}
}
#[derive(Clone, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub enum EntryKind {
Directory,
File(FileContent),
Symlink(Vec<u8>),
HardLink {
target: Vec<u8>,
},
CharDevice {
major: u32,
minor: u32,
},
BlockDevice {
major: u32,
minor: u32,
},
Fifo,
Socket,
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct SourceEntry {
pub path: Vec<u8>,
pub kind: EntryKind,
pub meta: Metadata,
pub xattrs: Vec<Xattr>,
}
pub trait Source {
fn into_entries(self) -> Vec<SourceEntry>;
}
#[derive(Clone, Default, Debug)]
pub struct TreeBuilder {
entries: Vec<SourceEntry>,
}
impl TreeBuilder {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn directory(mut self, path: impl Into<Vec<u8>>, meta: Metadata) -> Self {
self.push(path, EntryKind::Directory, meta);
self
}
#[must_use]
pub fn root(mut self, meta: Metadata) -> Self {
self.push(b"/".to_vec(), EntryKind::Directory, meta);
self
}
#[must_use]
pub fn file(
mut self,
path: impl Into<Vec<u8>>,
contents: impl Into<FileContent>,
meta: Metadata,
) -> Self {
self.push(path, EntryKind::File(contents.into()), meta);
self
}
#[must_use]
pub fn symlink(
mut self,
path: impl Into<Vec<u8>>,
target: impl Into<Vec<u8>>,
meta: Metadata,
) -> Self {
self.push(path, EntryKind::Symlink(target.into()), meta);
self
}
#[must_use]
pub fn hardlink(
mut self,
path: impl Into<Vec<u8>>,
target: impl Into<Vec<u8>>,
meta: Metadata,
) -> Self {
self.push(
path,
EntryKind::HardLink {
target: target.into(),
},
meta,
);
self
}
#[must_use]
pub fn char_device(
mut self,
path: impl Into<Vec<u8>>,
major: u32,
minor: u32,
meta: Metadata,
) -> Self {
self.push(path, EntryKind::CharDevice { major, minor }, meta);
self
}
#[must_use]
pub fn block_device(
mut self,
path: impl Into<Vec<u8>>,
major: u32,
minor: u32,
meta: Metadata,
) -> Self {
self.push(path, EntryKind::BlockDevice { major, minor }, meta);
self
}
#[must_use]
pub fn fifo(mut self, path: impl Into<Vec<u8>>, meta: Metadata) -> Self {
self.push(path, EntryKind::Fifo, meta);
self
}
#[must_use]
pub fn socket(mut self, path: impl Into<Vec<u8>>, meta: Metadata) -> Self {
self.push(path, EntryKind::Socket, meta);
self
}
#[must_use]
pub fn xattr(mut self, name: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>) -> Self {
if let Some(entry) = self.entries.last_mut() {
entry.xattrs.push(Xattr {
name: name.into(),
value: value.into(),
});
}
self
}
fn push(&mut self, path: impl Into<Vec<u8>>, kind: EntryKind, meta: Metadata) {
self.entries.push(SourceEntry {
path: path.into(),
kind,
meta,
xattrs: Vec::new(),
});
}
}
impl Source for TreeBuilder {
fn into_entries(self) -> Vec<SourceEntry> {
self.entries
}
}
#[derive(Clone, Default, Debug)]
pub struct LayeredSource {
entries: BTreeMap<Vec<u8>, SourceEntry>,
}
impl LayeredSource {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn layer(mut self, source: impl Source) -> Self {
for entry in source.into_entries() {
let key = canonical_key(&entry.path);
if !matches!(entry.kind, EntryKind::Directory) {
let mut prefix = key.clone();
if !prefix.is_empty() {
prefix.push(b'/');
}
let doomed: Vec<Vec<u8>> = self
.entries
.range(prefix.clone()..)
.take_while(|(k, _)| k.starts_with(&prefix))
.filter(|(k, _)| **k != key)
.map(|(k, _)| k.clone())
.collect();
for k in doomed {
self.entries.remove(&k);
}
}
self.entries.insert(key, entry);
}
self
}
#[must_use]
pub fn len(&self) -> usize {
self.entries.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.entries.is_empty()
}
}
impl Source for LayeredSource {
fn into_entries(self) -> Vec<SourceEntry> {
self.entries.into_values().collect()
}
}
#[cfg(any(feature = "fat", feature = "exfat", feature = "btrfs"))]
pub(crate) enum PathFault {
Traversal,
Duplicate,
RootNotDirectory,
}
#[cfg(any(feature = "fat", feature = "exfat", feature = "btrfs"))]
pub(crate) enum ClassifyError<E> {
Path(PathFault, Vec<u8>),
Class(E),
}
#[cfg(any(feature = "fat", feature = "exfat", feature = "btrfs"))]
pub(crate) fn classify_paths<C, E>(
entries: &[SourceEntry],
mut class_of: impl FnMut(&SourceEntry, &[&[u8]]) -> Result<C, E>,
is_directory: impl Fn(&C) -> bool,
) -> Result<BTreeMap<Vec<u8>, C>, ClassifyError<E>> {
let mut classes = BTreeMap::new();
for entry in entries {
let parts = crate::path::canonical_parts(&entry.path);
if parts.iter().any(|part| *part == b"..") {
return Err(ClassifyError::Path(
PathFault::Traversal,
entry.path.clone(),
));
}
let key = parts.join(&b'/');
if classes.contains_key(&key) {
return Err(ClassifyError::Path(
PathFault::Duplicate,
entry.path.clone(),
));
}
let class = class_of(entry, &parts).map_err(ClassifyError::Class)?;
if key.is_empty() && !is_directory(&class) {
return Err(ClassifyError::Path(
PathFault::RootNotDirectory,
entry.path.clone(),
));
}
classes.insert(key, class);
}
Ok(classes)
}
#[cfg(any(feature = "fat", feature = "exfat"))]
pub(crate) enum LinkStep<T> {
File(T),
Directory,
Unrepresentable,
Link(Vec<u8>),
Missing,
}
#[cfg(any(feature = "fat", feature = "exfat"))]
pub(crate) enum LinkEnd<T> {
File(T),
Unrepresentable,
Directory,
Missing,
Cycle,
}
#[cfg(any(feature = "fat", feature = "exfat"))]
pub(crate) fn follow_hard_link<T>(
target: &[u8],
declared: usize,
step: impl Fn(&[u8]) -> LinkStep<T>,
) -> LinkEnd<T> {
let mut at = canonical_key(target);
let mut seen = 0usize;
loop {
match step(&at) {
LinkStep::File(found) => return LinkEnd::File(found),
LinkStep::Directory => return LinkEnd::Directory,
LinkStep::Unrepresentable => return LinkEnd::Unrepresentable,
LinkStep::Missing => return LinkEnd::Missing,
LinkStep::Link(next) => {
seen += 1;
if seen > declared {
return LinkEnd::Cycle;
}
at = next;
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn meta() -> Metadata {
Metadata::new(0o644, Timestamp::from_secs(1_700_000_000))
}
#[test]
fn builder_collects_entries_in_addition_order() {
let src = TreeBuilder::new()
.directory(b"/etc".to_vec(), Metadata::new(0o755, meta().mtime))
.file(b"/etc/hostname".to_vec(), b"host\n".to_vec(), meta())
.symlink(b"/etc/mtab".to_vec(), b"/proc/mounts".to_vec(), meta());
let entries = src.into_entries();
assert_eq!(entries.len(), 3);
assert_eq!(entries[0].path, b"/etc");
assert!(matches!(entries[1].kind, EntryKind::File(_)));
assert!(matches!(entries[2].kind, EntryKind::Symlink(_)));
}
fn paths(source: LayeredSource) -> Vec<String> {
source
.into_entries()
.into_iter()
.map(|e| String::from_utf8_lossy(&e.path).into_owned())
.collect()
}
fn contents_at(entries: &[SourceEntry], path: &[u8]) -> Vec<u8> {
let entry = entries
.iter()
.find(|e| e.path == path)
.expect("path is present");
match &entry.kind {
EntryKind::File(c) => c.read().expect("read").into_owned(),
other => panic!("expected a file, got {other:?}"),
}
}
#[test]
fn a_later_layer_replaces_an_earlier_entry_whole() {
let base = TreeBuilder::new()
.file(b"/etc/hostname".to_vec(), b"base\n".to_vec(), meta())
.xattr(b"user.from".to_vec(), b"base".to_vec());
let over = TreeBuilder::new()
.file(
b"/etc/hostname".to_vec(),
b"over\n".to_vec(),
Metadata::new(0o600, meta().mtime),
)
.xattr(b"user.other".to_vec(), b"over".to_vec());
let entries = LayeredSource::new().layer(base).layer(over).into_entries();
assert_eq!(entries.len(), 1);
assert_eq!(contents_at(&entries, b"/etc/hostname"), b"over\n");
assert_eq!(entries[0].meta.mode, 0o600);
assert_eq!(entries[0].xattrs.len(), 1);
assert_eq!(entries[0].xattrs[0].name, b"user.other");
}
#[test]
fn naming_a_directory_again_does_not_empty_it() {
let base = TreeBuilder::new()
.directory(b"/etc".to_vec(), Metadata::new(0o755, meta().mtime))
.file(b"/etc/hostname".to_vec(), b"base\n".to_vec(), meta());
let over = TreeBuilder::new()
.directory(b"/etc".to_vec(), Metadata::new(0o700, meta().mtime))
.file(b"/etc/issue".to_vec(), b"over\n".to_vec(), meta());
let composed = LayeredSource::new().layer(base).layer(over);
assert_eq!(
paths(composed.clone()),
["/etc", "/etc/hostname", "/etc/issue"]
);
let entries = composed.into_entries();
assert_eq!(entries[0].meta.mode, 0o700, "the later layer's mode");
}
#[test]
fn replacing_a_directory_with_a_file_drops_what_was_beneath_it() {
let base = TreeBuilder::new()
.directory(b"/etc".to_vec(), Metadata::new(0o755, meta().mtime))
.file(b"/etc/hostname".to_vec(), b"base\n".to_vec(), meta())
.directory(b"/etc/ssl".to_vec(), Metadata::new(0o755, meta().mtime))
.file(b"/etc/ssl/cert".to_vec(), b"pem\n".to_vec(), meta())
.file(b"/etcetera".to_vec(), b"kept\n".to_vec(), meta());
let over = TreeBuilder::new().file(b"/etc".to_vec(), b"now a file\n".to_vec(), meta());
assert_eq!(
paths(LayeredSource::new().layer(base).layer(over)),
["/etc", "/etcetera"]
);
}
#[test]
fn a_directory_over_a_file_keeps_the_directory() {
let base = TreeBuilder::new().file(b"/etc".to_vec(), b"a file\n".to_vec(), meta());
let over = TreeBuilder::new()
.directory(b"/etc".to_vec(), Metadata::new(0o755, meta().mtime))
.file(b"/etc/hostname".to_vec(), b"over\n".to_vec(), meta());
let entries = LayeredSource::new().layer(base).layer(over).into_entries();
assert_eq!(entries.len(), 2);
assert!(matches!(entries[0].kind, EntryKind::Directory));
}
#[test]
fn paths_that_spell_one_path_are_one_path() {
let base = TreeBuilder::new().file(b"/etc/hostname".to_vec(), b"base\n".to_vec(), meta());
let over = TreeBuilder::new().file(b"//etc//hostname".to_vec(), b"over\n".to_vec(), meta());
let last = TreeBuilder::new().file(b"etc/./hostname".to_vec(), b"last\n".to_vec(), meta());
let entries = LayeredSource::new()
.layer(base)
.layer(over)
.layer(last)
.into_entries();
assert_eq!(entries.len(), 1, "three spellings of one path");
assert_eq!(entries[0].path, b"etc/./hostname");
assert_eq!(contents_at(&entries, b"etc/./hostname"), b"last\n");
}
#[test]
fn the_root_is_a_path_like_any_other() {
let base = TreeBuilder::new()
.root(Metadata::new(0o755, meta().mtime))
.file(b"/etc/hostname".to_vec(), b"base\n".to_vec(), meta());
let over = TreeBuilder::new().root(Metadata::new(0o700, meta().mtime));
let composed = LayeredSource::new().layer(base).layer(over);
assert_eq!(paths(composed.clone()), ["/", "/etc/hostname"]);
assert_eq!(
composed.into_entries()[0].meta.mode,
0o700,
"the later root's mode, and the tree beneath it kept"
);
}
#[test]
fn a_layer_over_nothing_is_that_layer() {
let one = TreeBuilder::new().file(b"/a".to_vec(), b"x".to_vec(), meta());
assert_eq!(paths(LayeredSource::new().layer(one)), ["/a"]);
assert!(LayeredSource::new().is_empty());
assert_eq!(LayeredSource::new().len(), 0);
}
#[test]
fn metadata_ownership_builder() {
let m = Metadata::new(0o600, Timestamp::from_secs(0)).owned_by(1000, 1000);
assert_eq!(m.uid, 1000);
assert_eq!(m.gid, 1000);
assert_eq!(m.mode, 0o600);
}
#[test]
fn hardlink_records_its_target() {
let src = TreeBuilder::new()
.file(b"/a".to_vec(), b"x".to_vec(), meta())
.hardlink(b"/b".to_vec(), b"/a".to_vec(), meta());
let entries = src.into_entries();
match &entries[1].kind {
EntryKind::HardLink { target } => assert_eq!(target, b"/a"),
other => panic!("expected hardlink, got {other:?}"),
}
}
#[test]
fn device_fifo_and_socket_kinds_are_recorded() {
let entries = TreeBuilder::new()
.char_device(b"/dev/null".to_vec(), 1, 3, meta())
.block_device(b"/dev/sda".to_vec(), 8, 0, meta())
.fifo(b"/run/pipe".to_vec(), meta())
.socket(b"/run/sock".to_vec(), meta())
.into_entries();
assert!(matches!(
entries[0].kind,
EntryKind::CharDevice { major: 1, minor: 3 }
));
assert!(matches!(
entries[1].kind,
EntryKind::BlockDevice { major: 8, minor: 0 }
));
assert!(matches!(entries[2].kind, EntryKind::Fifo));
assert!(matches!(entries[3].kind, EntryKind::Socket));
}
#[test]
fn xattr_attaches_to_the_most_recent_entry() {
let entries = TreeBuilder::new()
.file(b"/bin/ping".to_vec(), b"elf".to_vec(), meta())
.xattr(b"security.capability".to_vec(), vec![1, 2, 3, 4])
.xattr(b"user.note".to_vec(), b"hi".to_vec())
.file(b"/plain".to_vec(), b"x".to_vec(), meta())
.into_entries();
assert_eq!(entries[0].xattrs.len(), 2);
assert_eq!(entries[0].xattrs[0].name, b"security.capability");
assert!(entries[1].xattrs.is_empty());
}
#[test]
fn xattr_without_a_preceding_entry_is_a_no_op() {
let entries = TreeBuilder::new()
.xattr(b"user.orphan".to_vec(), b"v".to_vec())
.into_entries();
assert!(entries.is_empty());
}
#[test]
fn every_borrowed_form_of_a_files_bytes_converts() {
let want = EntryKind::File(FileContent::Owned(b"hi".to_vec()));
let entries = TreeBuilder::new()
.file(b"/vec".to_vec(), b"hi".to_vec(), meta())
.file(b"/array".to_vec(), b"hi", meta())
.file(b"/slice".to_vec(), &b"hi"[..], meta())
.file(b"/str".to_vec(), "hi", meta())
.file(b"/string".to_vec(), String::from("hi"), meta())
.into_entries();
assert_eq!(entries.len(), 5);
for entry in &entries {
assert_eq!(
entry.kind,
want,
"{} converted to something else",
String::from_utf8_lossy(&entry.path)
);
}
}
#[test]
fn reading_owned_contents_borrows_rather_than_copies() {
let content = FileContent::Owned(vec![9u8; 64]);
let FileContent::Owned(held) = &content else {
unreachable!("the content is owned")
};
let read = content.read().expect("an owned read cannot fail");
assert!(matches!(read, std::borrow::Cow::Borrowed(_)));
assert!(std::ptr::eq(read.as_ptr(), held.as_ptr()));
}
#[test]
fn a_short_backing_file_names_itself_and_the_range() {
let dir = tempfile::tempdir().expect("temp dir");
let path = dir.path().join("shrunk.tar");
std::fs::write(&path, b"only eight").expect("write the backing file");
let file = Arc::new(File::open(&path).expect("open the backing file"));
let range = FileRange::new(Arc::clone(&file), &path, 4, 4096);
let err = range
.read()
.expect_err("a range past the end cannot be read");
let text = err.to_string();
assert!(text.contains("shrunk.tar"), "{text}");
assert!(text.contains("4096"), "{text}");
assert!(text.contains("offset 4"), "{text}");
assert_eq!(err.kind(), std::io::ErrorKind::UnexpectedEof);
let content = FileContent::Range(FileRange::new(file, &path, 5, 5));
let read = content.read().expect("read the range");
assert!(matches!(read, std::borrow::Cow::Owned(_)));
assert_eq!(read.as_ref(), b"eight");
}
#[cfg(unix)]
#[test]
fn a_link_is_refused_by_the_flag_this_target_defines() {
let dir = tempfile::tempdir().expect("temp dir");
let target = dir.path().join("target");
std::fs::write(&target, b"pointed at\n").expect("write the target");
let link = dir.path().join("link");
std::os::unix::fs::symlink(&target, &link).expect("symlink");
let err = FileRange::at_path(&link, 0, 11)
.read()
.expect_err("a range naming a link reads nothing");
let text = err.to_string();
assert!(text.contains("link"), "{text}");
assert_eq!(
FileRange::at_path(&target, 0, 11).read().expect("read"),
b"pointed at\n"
);
}
#[test]
fn distinct_times_are_preserved() {
let m = Metadata::new(0o644, Timestamp::from_secs(100)).with_times(
Timestamp::from_secs(1),
Timestamp::from_secs(2),
Timestamp::from_secs(3),
);
assert_eq!(m.atime, Timestamp::from_secs(1));
assert_eq!(m.ctime, Timestamp::from_secs(2));
assert_eq!(m.mtime, Timestamp::from_secs(3));
}
}