Skip to content

Commit

Permalink
Fixing double insertion of encoding in locale.gen/locale.conf (#1421)
Browse files Browse the repository at this point in the history
* A temporary fix for #1200, in the long run we need something like what was mentioned in the issue comments: #1200 (comment)

* Enabled the use of modifier detection and getting it in right

* Mistaken a split

* Adding less strict decoding of output log, this in order to handle the more correct locale generation introduced in this PR.
  • Loading branch information
Torxed committed Aug 12, 2022
1 parent 7b4940e commit b1ab5ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion archinstall/lib/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def __getitem__(self, key :slice) -> Optional[bytes]:

def __repr__(self, *args :List[Any], **kwargs :Dict[str, Any]) -> str:
if self.session:
return self.session._trace_log.decode('UTF-8')
return self.session._trace_log.decode('UTF-8', errors='backslashreplace')
return ''

def __json__(self) -> Dict[str, Union[str, bool, List[str], Dict[str, Any], Optional[bool], Optional[Dict[str, Any]]]]:
Expand Down
21 changes: 19 additions & 2 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,27 @@ def set_locale(self, locale :str, encoding :str = 'UTF-8', *args :str, **kwargs
if not len(locale):
return True

modifier = ''

# This is a temporary patch to fix #1200
if '.' in locale:
locale, potential_encoding = locale.split('.', 1)

# Override encoding if encoding is set to the default parameter
# and the "found" encoding differs.
if encoding == 'UTF-8' and encoding != potential_encoding:
encoding = potential_encoding

# Make sure we extract the modifier, that way we can put it in if needed.
if '@' in locale:
locale, modifier = locale.split('@', 1)
modifier = f"@{modifier}"
# - End patch

with open(f'{self.target}/etc/locale.gen', 'a') as fh:
fh.write(f'{locale}.{encoding} {encoding}\n')
fh.write(f'{locale}.{encoding}{modifier} {encoding}\n')
with open(f'{self.target}/etc/locale.conf', 'w') as fh:
fh.write(f'LANG={locale}.{encoding}\n')
fh.write(f'LANG={locale}.{encoding}{modifier}\n')

return True if SysCommand(f'/usr/bin/arch-chroot {self.target} locale-gen').exit_code == 0 else False

Expand Down

0 comments on commit b1ab5ba

Please sign in to comment.