From f31ffaaf1754e4578127049844c14eba6bdda477 Mon Sep 17 00:00:00 2001 From: Volker-Weissmann <39418860+Volker-Weissmann@users.noreply.github.com> Date: Mon, 1 Feb 2021 18:48:48 +0100 Subject: [PATCH] bugfix concerning octal umasks (#8282) * bugfix concerning octal umasks * minor fix * spelling mistake --- mesonbuild/coredata.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 211efec26..a4ce96510 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -144,7 +144,14 @@ class UserIntegerOption(UserOption[int]): except ValueError: raise MesonException('Value string "%s" is not convertible to an integer.' % valuestring) -class UserUmaskOption(UserIntegerOption, UserOption[T.Union[str, int]]): +class OctalInt(int): + # NinjaBackend.get_user_option_args uses str() to converts it to a command line option + # UserUmaskOption.toint() uses int(str, 8) to convert it to an integer + # So we need to use oct instead of dec here if we do not want values to be misinterpreted. + def __str__(self): + return oct(int(self)) + +class UserUmaskOption(UserIntegerOption, UserOption[T.Union[str, OctalInt]]): def __init__(self, description: str, value: T.Any, yielding: T.Optional[bool] = None): super().__init__(description, (0, 0o777, value), yielding) self.choices = ['preserve', '0000-0777'] @@ -154,12 +161,12 @@ class UserUmaskOption(UserIntegerOption, UserOption[T.Union[str, int]]): return self.value return format(self.value, '04o') - def validate_value(self, value: T.Any) -> T.Union[str, int]: + def validate_value(self, value: T.Any) -> T.Union[str, OctalInt]: if value is None or value == 'preserve': return 'preserve' - return super().validate_value(value) + return OctalInt(super().validate_value(value)) - def toint(self, valuestring: T.Union[str, int]) -> int: + def toint(self, valuestring: T.Union[str, OctalInt]) -> int: try: return int(valuestring, 8) except ValueError as e: