You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ro...@apache.org on 2020/12/29 13:46:25 UTC

[buildstream] 13/19: Make roundtrip_dump allow group permissions

This is an automated email from the ASF dual-hosted git repository.

root pushed a commit to branch tlater/casd-socket-permissions
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 288bd39c5ecd74a5817f86159f0a2153515d3bd3
Author: Tristan Maat <tr...@codethink.co.uk>
AuthorDate: Thu Nov 7 16:16:51 2019 +0000

    Make roundtrip_dump allow group permissions
---
 src/buildstream/_yaml.pyx        |  6 ++++--
 src/buildstream/utils.py         | 13 ++++++++++++-
 tests/artifactcache/junctions.py |  2 +-
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index 797e10d..1658a70 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -486,14 +486,16 @@ def roundtrip_load_data(contents, *, filename=None):
 # Args:
 #    contents (Mapping or list): The content to write out as YAML.
 #    file (any): The file to write to
+#    group_accessible (bool): Whether the resulting file should be group accessible.
 #
-def roundtrip_dump(contents, file=None):
+def roundtrip_dump(contents, file=None, group_accessible=False):
     with ExitStack() as stack:
         if type(file) is str:
             from . import utils
-            f = stack.enter_context(utils.save_file_atomic(file, 'w'))
+            f = stack.enter_context(utils.save_file_atomic(file, 'w', group_accessible=group_accessible))
         elif hasattr(file, 'write'):
             f = file
         else:
             f = sys.stdout
         yaml.round_trip_dump(contents, f, Dumper=HardlineDumper)
+
diff --git a/src/buildstream/utils.py b/src/buildstream/utils.py
index e9f0fb7..9ca5a2b 100644
--- a/src/buildstream/utils.py
+++ b/src/buildstream/utils.py
@@ -567,7 +567,8 @@ def save_file_atomic(filename: str,
                      newline: Optional[str] = None,
                      closefd: bool = True,
                      opener: Optional[Callable[[str, int], int]] = None,
-                     tempdir: Optional[str] = None) -> Iterator[IO]:
+                     tempdir: Optional[str] = None,
+                     group_accessible: bool = False) -> Iterator[IO]:
     """Save a file with a temporary name and rename it into place when ready.
 
     This is a context manager which is meant for saving data to files.
@@ -620,6 +621,16 @@ def save_file_atomic(filename: str,
             # This operation is atomic, at least on platforms we care about:
             # https://bugs.python.org/issue8828
             os.replace(tempname, filename)
+            if group_accessible:
+                os.chmod(
+                    filename,
+                    stat.S_IWUSR |
+                    stat.S_IRUSR |
+                    stat.S_IXUSR |
+                    stat.S_IWGRP |
+                    stat.S_IRGRP |
+                    stat.S_IXGRP,
+                )
     except Exception:
         cleanup_tempfile()
         raise
diff --git a/tests/artifactcache/junctions.py b/tests/artifactcache/junctions.py
index dab69ea..32788ef 100644
--- a/tests/artifactcache/junctions.py
+++ b/tests/artifactcache/junctions.py
@@ -24,7 +24,7 @@ def project_set_artifacts(project, url):
         'url': url,
         'push': True
     }
-    _yaml.roundtrip_dump(project_config.strip_node_info(), file=project_conf_file)
+    _yaml.roundtrip_dump(project_config.strip_node_info(), file=project_conf_file, group_accessible=True)
 
 
 @pytest.mark.datafiles(DATA_DIR)