Skip to content

Commit

Permalink
fix: revert fix for (LP: #1827857)
Browse files Browse the repository at this point in the history
The fix was implemented in the `python3-apt` package. The changes in `landscape-client` now cause issues with package reporter on machines with certain locale configurations.
  • Loading branch information
wck0 committed Jul 22, 2024
1 parent f4c7f7e commit a5b9307
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 45 deletions.
2 changes: 1 addition & 1 deletion landscape/client/monitor/packagemonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _reset(self):
Remove all tasks *except* the resynchronize task. This is
because if we clear all tasks, then add the resynchronize,
it's possible that the reporter may be running a task at this
time and when it finishes, it will unknowningly remove the
time and when it finishes, it will unknowingly remove the
resynchronize task because sqlite resets its serial primary
keys when you delete an entire table. This problem is avoided
by adding the task first and removing them all *except* the
Expand Down
5 changes: 0 additions & 5 deletions landscape/client/package/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
except ImportError:
import urllib.parse as urlparse

import locale
import logging
import time
import os
Expand Down Expand Up @@ -940,10 +939,6 @@ def send_pending_messages(self):


def main(args):
# Force UTF-8 encoding only for the reporter, thus allowing libapt-pkg to
# return unmangled descriptions.
locale.setlocale(locale.LC_CTYPE, ("C", "UTF-8"))

if "FAKE_GLOBAL_PACKAGE_STORE" in os.environ:
return run_task_handler(FakeGlobalReporter, args)
elif "FAKE_PACKAGE_STORE" in os.environ:
Expand Down
29 changes: 0 additions & 29 deletions landscape/client/package/tests/test_reporter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import locale
import logging
import os
import shutil
Expand Down Expand Up @@ -1443,34 +1442,6 @@ def test_main(self):
self.assertEqual("RESULT", main(["ARGS"]))
m.assert_called_once_with(PackageReporter, ["ARGS"])

def test_main_resets_locale(self):
"""
Reporter entry point should reset encoding to utf-8, as libapt-pkg
encodes description with system encoding and python-apt decodes
them as utf-8 (LP: #1827857).
"""
self._add_package_to_deb_dir(
self.repository_dir,
"gosa",
description="GOsa\u00B2",
)
self.facade.reload_channels()

# Set the only non-utf8 locale which we're sure exists.
# It behaves slightly differently than the bug, but fails on the
# same condition.
locale.setlocale(locale.LC_CTYPE, (None, None))
self.addCleanup(locale.resetlocale)

with mock.patch("landscape.client.package.reporter.run_task_handler"):
main([])

# With the actual package, the failure will occur looking up the
# description translation.
pkg = self.facade.get_packages_by_name("gosa")[0]
skel = self.facade.get_package_skeleton(pkg, with_info=True)
self.assertEqual("GOsa\u00B2", skel.description)

def test_find_reporter_command_with_bindir(self):
self.config.bindir = "/spam/eggs"
command = find_reporter_command(self.config)
Expand Down
12 changes: 2 additions & 10 deletions landscape/lib/apt/package/tests/test_skeleton.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import locale
import unittest

from twisted.python.compat import unicode
Expand Down Expand Up @@ -193,15 +192,8 @@ def test_build_skeleton_with_unicode_and_extra_info(self):
def test_build_skeleton_with_unicode_and_non_ascii(self):
"""
If with_unicode and with_info are passed to build_skeleton_apt,
the description is decoded.
the description is decoded and non-ascii chars replaced.
"""
# Py2 used to convert to lossy ascii (thus LC_ in Makefile)
# Py3 doesn't, and python3-apt assumes UTF8 (LP: #1827857).
# If you revisit this test, also check reporter.main(), which
# should set this globally to the reporter process.
locale.setlocale(locale.LC_CTYPE, "C.UTF-8")
self.addCleanup(locale.resetlocale)

self._add_package_to_deb_dir(
self.skeleton_repository_dir,
"pkg",
Expand All @@ -211,7 +203,7 @@ def test_build_skeleton_with_unicode_and_non_ascii(self):
self.facade._cache.open(None)
pkg = self.get_package("pkg")
skeleton = build_skeleton_apt(pkg, with_unicode=True, with_info=True)
self.assertEqual("T\u00E9st", skeleton.description)
self.assertEqual("T?st", skeleton.description)

def test_build_skeleton_minimal(self):
"""
Expand Down

0 comments on commit a5b9307

Please sign in to comment.