Skip to content

rewrite check_files_md5 in pure Python - #643

Merged
bdrung merged 1 commit into
canonical:mainfrom
bdrung:md5sum
Aug 18, 2026
Merged

rewrite check_files_md5 in pure Python#643
bdrung merged 1 commit into
canonical:mainfrom
bdrung:md5sum

Conversation

@bdrung

@bdrung bdrung commented Jul 28, 2026

Copy link
Copy Markdown
Member

GNU coreutils 9.11 and rust-coreutils 0.9 changed md5sum to quote the filenames in case they contain spaces or other special characters. Example:

$ echo first > "with spaces"
$ echo second > "with'quotes"
$ echo third > 'with"quotes'
$ echo fourth > "with \" and ' quotes"
$ md5sum "with spaces" "with'quotes" 'with"quotes' "with \" and ' quotes" > sums
$ md5sum -c sums
'with spaces': OK
"with'quotes": OK
'with"quotes': OK
'with " and '\'' quotes': OK

This new quoting could be supported by checking for single or double quotes and use shlex.split in these cases.

To make the code more robust do not rely on the md5sum command and just use pure Python for it.

Bug: https://launchpad.net/bugs/2161957

@bdrung bdrung changed the title fileutils: rewrite check_files_md5 in pure Python rewrite check_files_md5 in pure Python Jul 28, 2026
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.45%. Comparing base (816e891) to head (4f49118).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
apport/packaging_impl/apt_dpkg.py 53.84% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #643      +/-   ##
==========================================
- Coverage   84.49%   84.45%   -0.04%     
==========================================
  Files         106      106              
  Lines       21018    20996      -22     
  Branches     3195     3187       -8     
==========================================
- Hits        17759    17733      -26     
- Misses       2785     2791       +6     
+ Partials      474      472       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Hyask Hyask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved because your changes keep the current logic, but that function is super brittle and would need some rework.

Comment thread apport/packaging_impl/apt_dpkg.py Outdated
Comment thread apport/packaging_impl/apt_dpkg.py Outdated
@bdrung
bdrung force-pushed the md5sum branch 2 times, most recently from eecf74e to 0f4a950 Compare August 18, 2026 12:17
@bdrung
bdrung requested a review from Hyask August 18, 2026 12:18

@Hyask Hyask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great change!

GNU coreutils 9.11 and rust-coreutils 0.9 changed `md5sum` to quote the
filenames in case they contain spaces or other special characters.
Example:

```
$ echo first > "with spaces"
$ echo second > "with'quotes"
$ echo third > 'with"quotes'
$ echo fourth > "with \" and ' quotes"
$ md5sum "with spaces" "with'quotes" 'with"quotes' "with \" and ' quotes" > sums
$ md5sum -c sums
'with spaces': OK
"with'quotes": OK
'with"quotes': OK
'with " and '\'' quotes': OK
```

This new quoting could be supported by checking for single or double
quotes and use `shlex.split` in these cases.

To make the code more robust do not rely on the `md5sum` command and
just use pure Python for it.

Bug: https://launchpad.net/bugs/2161957
@bdrung

bdrung commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

Just rebased.

@bdrung
bdrung merged commit 4f49118 into canonical:main Aug 18, 2026
26 of 28 checks passed
@bdrung
bdrung deleted the md5sum branch August 18, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants