mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Revert back to using reg to get timezone
Reverts PR 51095 Checks for null characters
This commit is contained in:
parent
892cdaeaa7
commit
59b1d4f767
1 changed files with 11 additions and 10 deletions
|
@ -205,22 +205,23 @@ def get_zone():
|
|||
Returns:
|
||||
str: Timezone in unix format
|
||||
|
||||
Raises:
|
||||
CommandExecutionError: If timezone could not be gathered
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' timezone.get_zone
|
||||
'''
|
||||
cmd = ['tzutil', '/g']
|
||||
res = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
if res['retcode'] or not res['stdout']:
|
||||
raise CommandExecutionError('tzutil encountered an error getting '
|
||||
'timezone',
|
||||
info=res)
|
||||
return mapper.get_unix(res['stdout'].lower(), 'Unknown')
|
||||
win_zone = __utils__['reg.read_value'](
|
||||
hive='HKLM',
|
||||
key='SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation',
|
||||
vname='TimeZoneKeyName')['vdata']
|
||||
# Some data may have null characters. We only need the first portion up to
|
||||
# the first null character. See the following:
|
||||
# https://github.com/saltstack/salt/issues/51940
|
||||
# https://stackoverflow.com/questions/27716746/hklm-system-currentcontrolset-control-timezoneinformation-timezonekeyname-corrup
|
||||
if '\0' in win_zone:
|
||||
win_zone = win_zone.split('\0')[0]
|
||||
return mapper.get_unix(win_zone.lower(), 'Unknown')
|
||||
|
||||
|
||||
def get_offset():
|
||||
|
|
Loading…
Add table
Reference in a new issue