apport-hackers team mailing list archive
-
apport-hackers team
-
Mailing list archive
-
Message #00320
[Merge] lp:~bdrung/apport/lp-1684600-gnu-linux into lp:apport
Benjamin Drung has proposed merging lp:~bdrung/apport/lp-1684600-gnu-linux into lp:apport.
Requested reviews:
Apport upstream developers (apport-hackers)
Related bugs:
Bug #1684600 in Apport: "DistroRelease which contains slashes used in path"
https://bugs.launchpad.net/apport/+bug/1684600
For more details, see:
https://code.launchpad.net/~bdrung/apport/lp-1684600-gnu-linux/+merge/389659
Fix stripping GNU/Linux from DistroRelease
The DistroRelease contains GNU/Linux on Debian (example: "Debian
GNU/Linux 8"). The containing slash is very confusing when using the
DistroRelease as path.
name[1:-2] strips one leading characters and two trailing characters and
removes one character too much at the end. Thus the name.endswith check
fails to match 'GNU/Linux' and does nothing. If it was matching
GNU/Linux, it would set name to a list.
Fix the parsing of /etc/os-release by using shlex.
--
Your team Apport upstream developers is requested to review the proposed merge of lp:~bdrung/apport/lp-1684600-gnu-linux into lp:apport.
=== modified file 'apport/packaging.py'
--- apport/packaging.py 2017-06-12 23:42:53 +0000
+++ apport/packaging.py 2020-08-21 15:18:13 +0000
@@ -12,6 +12,7 @@
import os
import sys
import re
+import shlex
import subprocess
@@ -284,17 +285,12 @@
version = None
with open('/etc/os-release') as f:
for l in f:
- if l.startswith('NAME='):
- name = l.split('=', 1)[1]
- if name.startswith('"'):
- name = name[1:-2].strip()
- # work around inconsistent "Debian GNU/Linux" in os-release
- if name.endswith('GNU/Linux'):
- name = name.split()[0:-1]
- elif l.startswith('VERSION_ID='):
- version = l.split('=', 1)[1]
- if version.startswith('"'):
- version = version[1:-2].strip()
+ key, value = shlex.split(l)[0].split("=", 1)
+ if key == "NAME":
+ # The OS name might be used as path later. Thus avoid / in the name.
+ name = value[:-9].strip() if value.endswith("GNU/Linux") else value
+ if key == "VERSION_ID":
+ version = value
if name and version:
self._os_version = (name, version)
return self._os_version