Skip to content

Commit b92aa3d

Browse files
mergify[bot]donoghucjsvd
authored
[8.18] (backport #18091) Preserve mtime explicitly when creating tar artifacts (#18109)
* Preserve mtime explicitly when creating tar artifacts (#18091) * Preserve mtime explicitly when creating tar artifacts When building tar archives, explicitly set mtime. This avoids losing that information in the minitar `Writer.add_file_simple` method https://github.com/halostatue/minitar/blob/a531136b17b9efdddf0a0f39537845b454c2371e/lib/minitar/writer.rb#L139 * Better default for mtime If for some reason we cant get a time from a File object (very unlikely) a better default is Time.now rather than 0. * Update rakelib/artifacts.rake Co-authored-by: João Duarte <[email protected]> --------- Co-authored-by: João Duarte <[email protected]> (cherry picked from commit d9b95bf) # Conflicts: # rakelib/artifacts.rake * 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]> * fix merge conflicts --------- Co-authored-by: Cas Donoghue <[email protected]> Co-authored-by: João Duarte <[email protected]>
1 parent 0aac377 commit b92aa3d

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

562562
def write_to_tar(tar, path, path_in_tar)
563563
stat = File.lstat(path)
564+
# in the off-chance that mtime returns nil we don't want nil to be interpreted as epoch, so fall back to Time.now
565+
mtime = (stat.mtime || Time.now).to_i
564566
if stat.directory?
565-
tar.mkdir(path_in_tar, :mode => stat.mode)
567+
tar.mkdir(path_in_tar, :mode => stat.mode, :mtime => mtime)
566568
elsif stat.symlink?
567-
tar.symlink(path_in_tar, File.readlink(path), :mode => stat.mode)
569+
tar.symlink(path_in_tar, File.readlink(path), :mode => stat.mode, :mtime => mtime)
568570
else
569-
tar.add_file_simple(path_in_tar, :mode => stat.mode, :size => stat.size) do |io|
571+
tar.add_file_simple(path_in_tar, :mode => stat.mode, :size => stat.size, :mtime => mtime) do |io|
570572
File.open(path, 'rb') do |fd|
571573
chunk = nil
572574
size = 0

0 commit comments

Comments
 (0)