Skip to content

Commit ef97a87

Browse files
donoghucjsvd
andauthored
Ensure any file object in a tar archive has an mtime (#18113)
* Ensure any file object in a tar archive has an mtime Following up on #18091, when minitar writes a directory or symlink it also needs explicit mtime. After inspecting artifacts built from #18019 we see some other missing mtimes. This commit ensures that information is explicitly passed to the minitar writer. * Update rakelib/artifacts.rake Co-authored-by: João Duarte <[email protected]> --------- Co-authored-by: João Duarte <[email protected]>
1 parent d2baf9f commit ef97a87

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

rakelib/artifacts.rake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,14 @@ namespace "artifact" do
664664

665665
def write_to_tar(tar, path, path_in_tar)
666666
stat = File.lstat(path)
667+
# in the off-chance that mtime returns nil we don't want nil to be interpreted as epoch, so fall back to Time.now
668+
mtime = (stat.mtime || Time.now).to_i
667669
if stat.directory?
668-
tar.mkdir(path_in_tar, :mode => stat.mode)
670+
tar.mkdir(path_in_tar, :mode => stat.mode, :mtime => mtime)
669671
elsif stat.symlink?
670-
tar.symlink(path_in_tar, File.readlink(path), :mode => stat.mode)
672+
tar.symlink(path_in_tar, File.readlink(path), :mode => stat.mode, :mtime => mtime)
671673
else
672-
tar.add_file_simple(path_in_tar, :mode => stat.mode, :size => stat.size, :mtime => (stat.mtime || Time.now).to_i) do |io|
674+
tar.add_file_simple(path_in_tar, :mode => stat.mode, :size => stat.size, :mtime => mtime) do |io|
673675
File.open(path, 'rb') do |fd|
674676
chunk = nil
675677
size = 0

0 commit comments

Comments
 (0)