diff options
author | Ross Burton <ross@burtonini.com> | 2020-09-28 17:18:58 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-09-30 15:03:30 +0100 |
commit | f3b0d3eeaefa4ecbc1c31406201ebc03e5bf1588 (patch) | |
tree | e354f8c5069101339c95ee0475ea55626beca6d0 | |
parent | f6609eebca510b298f46074059f1643017166a49 (diff) | |
download | poky-f3b0d3eeaefa4ecbc1c31406201ebc03e5bf1588.tar.gz |
bitbake: utils: add umask changing context manager
Add a umask context manager which can be used to temporarily change the
umask in a 'with' block.
(Bitbake rev: 6c601e68a27e1c60b04c2a61830d1812cc883e09)
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 0b79f92e25..f73d31fb73 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -944,6 +944,17 @@ def which(path, item, direction = 0, history = False, executable=False): | |||
944 | return "", hist | 944 | return "", hist |
945 | return "" | 945 | return "" |
946 | 946 | ||
947 | @contextmanager | ||
948 | def umask(new_mask): | ||
949 | """ | ||
950 | Context manager to set the umask to a specific mask, and restore it afterwards. | ||
951 | """ | ||
952 | current_mask = os.umask(new_mask) | ||
953 | try: | ||
954 | yield | ||
955 | finally: | ||
956 | os.umask(current_mask) | ||
957 | |||
947 | def to_boolean(string, default=None): | 958 | def to_boolean(string, default=None): |
948 | if not string: | 959 | if not string: |
949 | return default | 960 | return default |