Skip to content

Commit

Permalink
Allow users to opt into mtime preservation (#1489)
Browse files Browse the repository at this point in the history
  • Loading branch information
dannysullivan authored May 6, 2020
1 parent 734ed53 commit 972f3eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions container/build_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
' value "portable", to get the value 2000-01-01, which is'
' usable with non *nix OSes.')

gflags.DEFINE_bool(
'enable_mtime_preservation', False, 'Preserve file mtimes from input tar file.')

gflags.DEFINE_multistring(
'empty_root_dir',
[],
Expand Down Expand Up @@ -121,12 +124,14 @@ def parse_pkg_name(metadata, filename):
else:
return os.path.basename(os.path.splitext(filename)[0])

def __init__(self, output, directory, compression, root_directory, default_mtime):
def __init__(self, output, directory, compression, root_directory,
default_mtime, enable_mtime_preservation):
self.directory = directory
self.output = output
self.compression = compression
self.root_directory = root_directory
self.default_mtime = default_mtime
self.enable_mtime_preservation = enable_mtime_preservation

def __enter__(self):
self.tarfile = archive.TarFileWriter(
Expand Down Expand Up @@ -406,7 +411,9 @@ def main(unused_argv):
ids_map[f] = (int(user), int(group))

# Add objects to the tar file
with TarFile(FLAGS.output, FLAGS.directory, FLAGS.compression, FLAGS.root_directory, FLAGS.mtime) as output:
with TarFile(FLAGS.output, FLAGS.directory, FLAGS.compression,
FLAGS.root_directory, FLAGS.mtime,
FLAGS.enable_mtime_preservation) as output:
def file_attributes(filename):
if filename.startswith('/'):
filename = filename[1:]
Expand Down
4 changes: 3 additions & 1 deletion container/layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def build_layer(
args.add(ctx.attr.mtime, format = "--mtime=%s")
if ctx.attr.portable_mtime:
args.add("--mtime=portable")

if ctx.attr.enable_mtime_preservation:
args.add("--enable_mtime_preservation=true")
if toolchain_info.xz_path != "":
args.add(toolchain_info.xz_path, format = "--xz_path=%s")

Expand Down Expand Up @@ -275,6 +276,7 @@ _layer_attrs = dicts.add({
"empty_dirs": attr.string_list(),
# Implicit/Undocumented dependencies.
"empty_files": attr.string_list(),
"enable_mtime_preservation": attr.bool(default = False),
"env": attr.string_dict(),
"files": attr.label_list(allow_files = True),
"mode": attr.string(default = "0o555"), # 0o555 == a+rx
Expand Down

0 comments on commit 972f3eb

Please sign in to comment.