Skip to content
Snippets Groups Projects
Commit 8b34e356 authored by Angelos Evripiotis's avatar Angelos Evripiotis
Browse files

Merge branch 'aevri/mtime1' into 'master'

storage.Directory.export_to_tar: default mtime=utils._magic_timestamp

Closes #914

See merge request !1149
parents 14176e51 39febfda
No related branches found
No related tags found
1 merge request!1149storage.Directory.export_to_tar: default mtime=utils._magic_timestamp
Pipeline #47682800 passed
......@@ -36,7 +36,7 @@ from .._protos.build.bazel.remote.execution.v2 import remote_execution_pb2
from .._exceptions import BstError
from .directory import Directory, VirtualDirectoryError
from ._filebaseddirectory import FileBasedDirectory
from ..utils import FileListResult, safe_copy, list_relative_paths
from ..utils import FileListResult, safe_copy, list_relative_paths, _magic_timestamp
class IndexEntry():
......@@ -535,7 +535,7 @@ class CasBasedDirectory(Directory):
" The original error was: {}").
format(src_name, entry.target, e))
def export_to_tar(self, tarfile, destination_dir, mtime=0):
def export_to_tar(self, tarfile, destination_dir, mtime=_magic_timestamp):
raise NotImplementedError()
def mark_changed(self):
......
......@@ -157,7 +157,7 @@ class FileBasedDirectory(Directory):
# First, it sorts the results of os.listdir() to ensure the ordering of
# the files in the archive is the same. Second, it sets a fixed
# timestamp for each entry. See also https://bugs.python.org/issue24465.
def export_to_tar(self, tf, dir_arcname, mtime=0):
def export_to_tar(self, tf, dir_arcname, mtime=_magic_timestamp):
# We need directories here, including non-empty ones,
# so list_relative_paths is not used.
for filename in sorted(os.listdir(self.external_directory)):
......
......@@ -32,6 +32,7 @@ See also: :ref:`sandboxing`.
"""
from .._exceptions import BstError, ErrorDomain
from ..utils import _magic_timestamp
class VirtualDirectoryError(BstError):
......@@ -114,7 +115,7 @@ class Directory():
raise NotImplementedError()
def export_to_tar(self, tarfile, destination_dir, mtime=0):
def export_to_tar(self, tarfile, destination_dir, mtime=_magic_timestamp):
""" Exports this directory into the given tar file.
Args:
......
......@@ -252,6 +252,26 @@ def test_build_checkout_tarball_stdout(datafiles, cli):
assert os.path.join('.', 'usr', 'include', 'pony.h') in tar.getnames()
@pytest.mark.datafiles(DATA_DIR)
def test_build_checkout_tarball_mtime_nonzero(datafiles, cli):
project = os.path.join(datafiles.dirname, datafiles.basename)
tarpath = os.path.join(cli.directory, 'mtime_tar.tar')
result = cli.run(project=project, args=['build', 'target.bst'])
result.assert_success()
checkout_args = ['artifact', 'checkout', '--tar', tarpath, 'target.bst']
result = cli.run(project=project, args=checkout_args)
result.assert_success()
tar = tarfile.TarFile(tarpath)
for tarinfo in tar.getmembers():
# An mtime of zero can be confusing to other software,
# e.g. ninja build and template toolkit have both taken zero mtime to
# mean 'file does not exist'.
assert tarinfo.mtime > 0
@pytest.mark.datafiles(DATA_DIR)
def test_build_checkout_tarball_is_deterministic(datafiles, cli):
project = os.path.join(datafiles.dirname, datafiles.basename)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment