Skip to content

Commit 8e35ee0

Browse files
donoghucjsvd
andcommitted
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 e2af2a1 commit 8e35ee0

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
@@ -620,12 +620,14 @@ namespace "artifact" do
620620

621621
def write_to_tar(tar, path, path_in_tar)
622622
stat = File.lstat(path)
623+
# in the off-chance that mtime returns nil we don't want nil to be interpreted as epoch, so fall back to Time.now
624+
mtime = (stat.mtime || Time.now).to_i
623625
if stat.directory?
624-
tar.mkdir(path_in_tar, :mode => stat.mode)
626+
tar.mkdir(path_in_tar, :mode => stat.mode, :mtime => mtime)
625627
elsif stat.symlink?
626-
tar.symlink(path_in_tar, File.readlink(path), :mode => stat.mode)
628+
tar.symlink(path_in_tar, File.readlink(path), :mode => stat.mode, :mtime => mtime)
627629
else
628-
tar.add_file_simple(path_in_tar, :mode => stat.mode, :size => stat.size, :mtime => (stat.mtime || Time.now).to_i) do |io|
630+
tar.add_file_simple(path_in_tar, :mode => stat.mode, :size => stat.size, :mtime => mtime) do |io|
629631
File.open(path, 'rb') do |fd|
630632
chunk = nil
631633
size = 0

0 commit comments

Comments
 (0)