Valentin David pushed to branch master at BuildStream / buildstream
Commits:
-
478e5c47
by Valentin David at 2019-02-12T18:06:50Z
-
6de65306
by Valentin David at 2019-02-12T19:13:43Z
2 changed files:
Changes:
| ... | ... | @@ -376,9 +376,7 @@ class CASCache(): |
| 376 | 376 |
for chunk in iter(lambda: tmp.read(_BUFFER_SIZE), b""):
|
| 377 | 377 |
h.update(chunk)
|
| 378 | 378 |
else:
|
| 379 |
- tmp = stack.enter_context(utils._tempnamedfile(dir=self.tmpdir))
|
|
| 380 |
- # Set mode bits to 0644
|
|
| 381 |
- os.chmod(tmp.name, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
|
|
| 379 |
+ tmp = stack.enter_context(self._temporary_object())
|
|
| 382 | 380 |
|
| 383 | 381 |
if path:
|
| 384 | 382 |
with open(path, 'rb') as f:
|
| ... | ... | @@ -827,6 +825,19 @@ class CASCache(): |
| 827 | 825 |
for dirnode in directory.directories:
|
| 828 | 826 |
yield from self._required_blobs(dirnode.digest)
|
| 829 | 827 |
|
| 828 |
+ # _temporary_object():
|
|
| 829 |
+ #
|
|
| 830 |
+ # Returns:
|
|
| 831 |
+ # (file): A file object to a named temporary file.
|
|
| 832 |
+ #
|
|
| 833 |
+ # Create a named temporary file with 0o0644 access rights.
|
|
| 834 |
+ @contextlib.contextmanager
|
|
| 835 |
+ def _temporary_object(self):
|
|
| 836 |
+ with utils._tempnamedfile(dir=self.tmpdir) as f:
|
|
| 837 |
+ os.chmod(f.name,
|
|
| 838 |
+ stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
|
|
| 839 |
+ yield f
|
|
| 840 |
+ |
|
| 830 | 841 |
# _ensure_blob():
|
| 831 | 842 |
#
|
| 832 | 843 |
# Fetch and add blob if it's not already local.
|
| ... | ... | @@ -844,7 +855,7 @@ class CASCache(): |
| 844 | 855 |
# already in local repository
|
| 845 | 856 |
return objpath
|
| 846 | 857 |
|
| 847 |
- with utils._tempnamedfile(dir=self.tmpdir) as f:
|
|
| 858 |
+ with self._temporary_object() as f:
|
|
| 848 | 859 |
remote._fetch_blob(digest, f)
|
| 849 | 860 |
|
| 850 | 861 |
added_digest = self.add_object(path=f.name, link_directly=True)
|
| ... | ... | @@ -854,7 +865,7 @@ class CASCache(): |
| 854 | 865 |
|
| 855 | 866 |
def _batch_download_complete(self, batch):
|
| 856 | 867 |
for digest, data in batch.send():
|
| 857 |
- with utils._tempnamedfile(dir=self.tmpdir) as f:
|
|
| 868 |
+ with self._temporary_object() as f:
|
|
| 858 | 869 |
f.write(data)
|
| 859 | 870 |
f.flush()
|
| 860 | 871 |
|
| 1 | 1 |
import os
|
| 2 | 2 |
import shutil
|
| 3 |
+import stat
|
|
| 3 | 4 |
import pytest
|
| 4 | 5 |
from buildstream.plugintestutils import cli
|
| 5 | 6 |
from tests.testutils import create_artifact_share, generate_junction
|
| ... | ... | @@ -462,3 +463,74 @@ def test_build_remote_option(caplog, cli, tmpdir, datafiles): |
| 462 | 463 |
assert shareproject.repo not in result.stderr
|
| 463 | 464 |
assert shareuser.repo not in result.stderr
|
| 464 | 465 |
assert sharecli.repo in result.stderr
|
| 466 |
+ |
|
| 467 |
+ |
|
| 468 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
| 469 |
+def test_pull_access_rights(caplog, cli, tmpdir, datafiles):
|
|
| 470 |
+ project = str(datafiles)
|
|
| 471 |
+ checkout = os.path.join(str(tmpdir), 'checkout')
|
|
| 472 |
+ |
|
| 473 |
+ # Work-around datafiles not preserving mode
|
|
| 474 |
+ os.chmod(os.path.join(project, 'files/bin-files/usr/bin/hello'), 0o0755)
|
|
| 475 |
+ |
|
| 476 |
+ # We need a big file that does not go into a batch to test a different
|
|
| 477 |
+ # code path
|
|
| 478 |
+ os.makedirs(os.path.join(project, 'files/dev-files/usr/share'), exist_ok=True)
|
|
| 479 |
+ with open(os.path.join(project, 'files/dev-files/usr/share/big-file'), 'w') as f:
|
|
| 480 |
+ buf = ' ' * 4096
|
|
| 481 |
+ for _ in range(1024):
|
|
| 482 |
+ f.write(buf)
|
|
| 483 |
+ |
|
| 484 |
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
|
|
| 485 |
+ |
|
| 486 |
+ cli.configure({
|
|
| 487 |
+ 'artifacts': {'url': share.repo, 'push': True}
|
|
| 488 |
+ })
|
|
| 489 |
+ result = cli.run(project=project, args=['build', 'compose-all.bst'])
|
|
| 490 |
+ result.assert_success()
|
|
| 491 |
+ |
|
| 492 |
+ result = cli.run(project=project,
|
|
| 493 |
+ args=['artifact', 'checkout',
|
|
| 494 |
+ '--hardlinks', '--no-integrate',
|
|
| 495 |
+ 'compose-all.bst',
|
|
| 496 |
+ '--directory', checkout])
|
|
| 497 |
+ result.assert_success()
|
|
| 498 |
+ |
|
| 499 |
+ st = os.lstat(os.path.join(checkout, 'usr/include/pony.h'))
|
|
| 500 |
+ assert stat.S_ISREG(st.st_mode)
|
|
| 501 |
+ assert stat.S_IMODE(st.st_mode) == 0o0644
|
|
| 502 |
+ |
|
| 503 |
+ st = os.lstat(os.path.join(checkout, 'usr/bin/hello'))
|
|
| 504 |
+ assert stat.S_ISREG(st.st_mode)
|
|
| 505 |
+ assert stat.S_IMODE(st.st_mode) == 0o0755
|
|
| 506 |
+ |
|
| 507 |
+ st = os.lstat(os.path.join(checkout, 'usr/share/big-file'))
|
|
| 508 |
+ assert stat.S_ISREG(st.st_mode)
|
|
| 509 |
+ assert stat.S_IMODE(st.st_mode) == 0o0644
|
|
| 510 |
+ |
|
| 511 |
+ shutil.rmtree(checkout)
|
|
| 512 |
+ |
|
| 513 |
+ artifacts = os.path.join(cli.directory, 'artifacts')
|
|
| 514 |
+ shutil.rmtree(artifacts)
|
|
| 515 |
+ |
|
| 516 |
+ result = cli.run(project=project, args=['artifact', 'pull', 'compose-all.bst'])
|
|
| 517 |
+ result.assert_success()
|
|
| 518 |
+ |
|
| 519 |
+ result = cli.run(project=project,
|
|
| 520 |
+ args=['artifact', 'checkout',
|
|
| 521 |
+ '--hardlinks', '--no-integrate',
|
|
| 522 |
+ 'compose-all.bst',
|
|
| 523 |
+ '--directory', checkout])
|
|
| 524 |
+ result.assert_success()
|
|
| 525 |
+ |
|
| 526 |
+ st = os.lstat(os.path.join(checkout, 'usr/include/pony.h'))
|
|
| 527 |
+ assert stat.S_ISREG(st.st_mode)
|
|
| 528 |
+ assert stat.S_IMODE(st.st_mode) == 0o0644
|
|
| 529 |
+ |
|
| 530 |
+ st = os.lstat(os.path.join(checkout, 'usr/bin/hello'))
|
|
| 531 |
+ assert stat.S_ISREG(st.st_mode)
|
|
| 532 |
+ assert stat.S_IMODE(st.st_mode) == 0o0755
|
|
| 533 |
+ |
|
| 534 |
+ st = os.lstat(os.path.join(checkout, 'usr/share/big-file'))
|
|
| 535 |
+ assert stat.S_ISREG(st.st_mode)
|
|
| 536 |
+ assert stat.S_IMODE(st.st_mode) == 0o0644
|
