Angelos Evripiotis pushed to branch aevri/mtime1 at BuildStream / buildstream
Commits:
-
ed49da18
by Angelos Evripiotis at 2019-02-14T14:41:42Z
4 changed files:
- buildstream/storage/_casbaseddirectory.py
- buildstream/storage/_filebaseddirectory.py
- buildstream/storage/directory.py
- tests/frontend/buildcheckout.py
Changes:
| ... | ... | @@ -36,7 +36,7 @@ from .._protos.build.bazel.remote.execution.v2 import remote_execution_pb2 |
| 36 | 36 |
from .._exceptions import BstError
|
| 37 | 37 |
from .directory import Directory, VirtualDirectoryError
|
| 38 | 38 |
from ._filebaseddirectory import FileBasedDirectory
|
| 39 |
-from ..utils import FileListResult, safe_copy, list_relative_paths
|
|
| 39 |
+from ..utils import FileListResult, safe_copy, list_relative_paths, _magic_timestamp
|
|
| 40 | 40 |
|
| 41 | 41 |
|
| 42 | 42 |
class IndexEntry():
|
| ... | ... | @@ -718,7 +718,7 @@ class CasBasedDirectory(Directory): |
| 718 | 718 |
" The original error was: {}").
|
| 719 | 719 |
format(src_name, entry.target, e))
|
| 720 | 720 |
|
| 721 |
- def export_to_tar(self, tarfile, destination_dir, mtime=0):
|
|
| 721 |
+ def export_to_tar(self, tarfile, destination_dir, mtime=_magic_timestamp):
|
|
| 722 | 722 |
raise NotImplementedError()
|
| 723 | 723 |
|
| 724 | 724 |
def mark_changed(self):
|
| ... | ... | @@ -157,7 +157,7 @@ class FileBasedDirectory(Directory): |
| 157 | 157 |
# First, it sorts the results of os.listdir() to ensure the ordering of
|
| 158 | 158 |
# the files in the archive is the same. Second, it sets a fixed
|
| 159 | 159 |
# timestamp for each entry. See also https://bugs.python.org/issue24465.
|
| 160 |
- def export_to_tar(self, tf, dir_arcname, mtime=0):
|
|
| 160 |
+ def export_to_tar(self, tf, dir_arcname, mtime=_magic_timestamp):
|
|
| 161 | 161 |
# We need directories here, including non-empty ones,
|
| 162 | 162 |
# so list_relative_paths is not used.
|
| 163 | 163 |
for filename in sorted(os.listdir(self.external_directory)):
|
| ... | ... | @@ -32,6 +32,7 @@ See also: :ref:`sandboxing`. |
| 32 | 32 |
"""
|
| 33 | 33 |
|
| 34 | 34 |
from .._exceptions import BstError, ErrorDomain
|
| 35 |
+from ..utils import _magic_timestamp
|
|
| 35 | 36 |
|
| 36 | 37 |
|
| 37 | 38 |
class VirtualDirectoryError(BstError):
|
| ... | ... | @@ -114,7 +115,7 @@ class Directory(): |
| 114 | 115 |
|
| 115 | 116 |
raise NotImplementedError()
|
| 116 | 117 |
|
| 117 |
- def export_to_tar(self, tarfile, destination_dir, mtime=0):
|
|
| 118 |
+ def export_to_tar(self, tarfile, destination_dir, mtime=_magic_timestamp):
|
|
| 118 | 119 |
""" Exports this directory into the given tar file.
|
| 119 | 120 |
|
| 120 | 121 |
Args:
|
| ... | ... | @@ -252,6 +252,26 @@ def test_build_checkout_tarball_stdout(datafiles, cli): |
| 252 | 252 |
assert os.path.join('.', 'usr', 'include', 'pony.h') in tar.getnames()
|
| 253 | 253 |
|
| 254 | 254 |
|
| 255 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 256 |
+def test_build_checkout_tarball_mtime_nonzero(datafiles, cli):
|
|
| 257 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
| 258 |
+ tarpath = os.path.join(cli.directory, 'mtime_tar.tar')
|
|
| 259 |
+ |
|
| 260 |
+ result = cli.run(project=project, args=['build', 'target.bst'])
|
|
| 261 |
+ result.assert_success()
|
|
| 262 |
+ |
|
| 263 |
+ checkout_args = ['artifact', 'checkout', '--tar', tarpath, 'target.bst']
|
|
| 264 |
+ result = cli.run(project=project, args=checkout_args)
|
|
| 265 |
+ result.assert_success()
|
|
| 266 |
+ |
|
| 267 |
+ tar = tarfile.TarFile(tarpath)
|
|
| 268 |
+ for tarinfo in tar.getmembers():
|
|
| 269 |
+ # An mtime of zero can be confusing to other software,
|
|
| 270 |
+ # e.g. ninja build and template toolkit have both taken zero mtime to
|
|
| 271 |
+ # mean 'file does not exist'.
|
|
| 272 |
+ assert tarinfo.mtime > 0
|
|
| 273 |
+ |
|
| 274 |
+ |
|
| 255 | 275 |
@pytest.mark.datafiles(DATA_DIR)
|
| 256 | 276 |
def test_build_checkout_tarball_is_deterministic(datafiles, cli):
|
| 257 | 277 |
project = os.path.join(datafiles.dirname, datafiles.basename)
|
