Skip to content

Commit c30c386

Browse files
mergify[bot]donoghucjsvd
authored
[8.19] (backport #18091) Preserve mtime explicitly when creating tar artifacts (#18110)
* 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) * 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]> --------- Co-authored-by: Cas Donoghue <[email protected]> Co-authored-by: João Duarte <[email protected]>
1 parent 397138c commit c30c386

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

654654
def write_to_tar(tar, path, path_in_tar)
655655
stat = File.lstat(path)
656+
# in the off-chance that mtime returns nil we don't want nil to be interpreted as epoch, so fall back to Time.now
657+
mtime = (stat.mtime || Time.now).to_i
656658
if stat.directory?
657-
tar.mkdir(path_in_tar, :mode => stat.mode)
659+
tar.mkdir(path_in_tar, :mode => stat.mode, :mtime => mtime)
658660
elsif stat.symlink?
659-
tar.symlink(path_in_tar, File.readlink(path), :mode => stat.mode)
661+
tar.symlink(path_in_tar, File.readlink(path), :mode => stat.mode, :mtime => mtime)
660662
else
661-
tar.add_file_simple(path_in_tar, :mode => stat.mode, :size => stat.size) do |io|
663+
tar.add_file_simple(path_in_tar, :mode => stat.mode, :size => stat.size, :mtime => mtime) do |io|
662664
File.open(path, 'rb') do |fd|
663665
chunk = nil
664666
size = 0

0 commit comments

Comments
 (0)