Skip to content

Commit

Permalink
cache last mtime calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Drung <bdrung@posteo.de>
  • Loading branch information
bdrung committed Aug 6, 2024
1 parent afa4d9f commit 6e4d732
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ fn read_cpio_and_print_long_format<R: Read + SeekForward, W: Write>(
now: i64,
user_group_cache: &mut UserGroupCache,
) -> Result<()> {
let mut last_mtime = 0;
let mut mtime_string: String = "".into();
loop {
let header = match read_cpio_header(file) {
Ok(header) => {
Expand All @@ -497,6 +499,10 @@ fn read_cpio_and_print_long_format<R: Read + SeekForward, W: Write>(
None => header.gid.to_string(),
};
let mode_string = header.mode_string();
if header.mtime != last_mtime || mtime_string.is_empty() {
last_mtime = header.mtime;
mtime_string = format_time(header.mtime, now)?;
};

if header.mode & MODE_FILETYPE_MASK == FILETYPE_SYMLINK {
let target = header.read_symlink_target(file)?;
Expand All @@ -508,7 +514,7 @@ fn read_cpio_and_print_long_format<R: Read + SeekForward, W: Write>(
user,
group,
header.filesize,
format_time(header.mtime, now)?,
mtime_string,
header.filename,
target
)?;
Expand All @@ -522,7 +528,7 @@ fn read_cpio_and_print_long_format<R: Read + SeekForward, W: Write>(
user,
group,
header.filesize,
format_time(header.mtime, now)?,
mtime_string,
header.filename
)?;
};
Expand Down

0 comments on commit 6e4d732

Please sign in to comment.