Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parsing options in sources.list (LP: #1822712) #148

Closed
wants to merge 2 commits into from

Conversation

xypron
Copy link

@xypron xypron commented Mar 27, 2023

In sources.list the enclosing brackets of the options are separated by spaces from option values, e.g.

deb [ arch=riscv64 ] http://ports.ubuntu.com/ubuntu-ports/ lunar main

Fixes: f7ab55f ("* apt/dpkg: Recognize options in apt sources.list. (LP: #1238620)")

@bdrung
Copy link
Collaborator

bdrung commented Mar 27, 2023

Thanks for developing a fix. Please add a test case for the crash. Maybe the better fix is to offload the parsing to python-apt instead?

@codecov
Copy link

codecov bot commented Mar 27, 2023

Codecov Report

Merging #148 (9b29db2) into main (22f4525) will decrease coverage by 35.44%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##             main     #148       +/-   ##
===========================================
- Coverage   81.95%   46.52%   -35.44%     
===========================================
  Files          87       74       -13     
  Lines       18197    17271      -926     
===========================================
- Hits        14914     8035     -6879     
- Misses       3283     9236     +5953     
Impacted Files Coverage Δ
apport/packaging_impl/apt_dpkg.py 78.35% <100.00%> (-5.26%) ⬇️
tests/system/test_packaging_apt_dpkg.py 99.08% <100.00%> (+0.06%) ⬆️

... and 58 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@schopin-pro
Copy link
Contributor

Using python-apt would give us deb822 compat for free, too :)

@xypron
Copy link
Author

xypron commented Mar 28, 2023

This finds the url:

import aptsources.sourceslist
source_entry = aptsources.sourceslist.SourceEntry('deb [ arch=riscv64 ] https://example.com/path release section')
print(source_entry.uri)

In sources.list the enclosing brackets of the options are separated by
spaces from option values, e.g.

    deb [ arch=riscv64 ] http://ports.ubuntu.com/ubuntu-ports/ lunar main

Fixes: f7ab55f ("* apt/dpkg: Recognize options in apt sources.list. (LP: #1238620)")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
@xypron
Copy link
Author

xypron commented Mar 28, 2023

Using python-apt would give us deb822 compat for free, too :)

This would require changing _get_mirror() which uses hard coded "/etc/apt/sources.list". DEB822 sources have the extension .sources.

@xypron
Copy link
Author

xypron commented Mar 28, 2023

Thanks for developing a fix. Please add a test case for the crash. Maybe the better fix is to offload the parsing to python-apt instead?

The assumption that all sources in /etc/apt/sources.list use the same url which is illegal. The whole class should be rewritten. But that is beyond the scope of a simple bug fix.

@xypron
Copy link
Author

xypron commented Mar 28, 2023

Test added

Provide a test for
__AptDpkgPackageInfo.get_primary_mirror_from_apt_sources().

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
@bdrung
Copy link
Collaborator

bdrung commented Apr 11, 2023

This finds the url:

import aptsources.sourceslist
source_entry = aptsources.sourceslist.SourceEntry('deb [ arch=riscv64 ] https://example.com/path release section')
print(source_entry.uri)

This code snippet is what we want to use instead of extending our parser further. I used your research and your test case and developed a fix that uses aptsources.sourceslist.SourceEntry: #154. Some of your test cases are not needed since they are already covered by test_mirror_from_apt_sources.

@bdrung
Copy link
Collaborator

bdrung commented Apr 12, 2023

Superseded by #154

@bdrung bdrung closed this Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants