Skip to content

Return checksums for empty files and add is_empty file info flag - #5595

Open
motalib6 wants to merge 2 commits into
aboutcode-org:developfrom
motalib6:fix-461-empty-file-checksums-is-empty
Open

motalib6 wants to merge 2 commits into
aboutcode-org:developfrom
motalib6:fix-461-empty-file-checksums-is-empty

Conversation

@motalib6

@motalib6 motalib6 commented Dec 5, 2026

Copy link
Copy Markdown

Fixes #461.

Empty files previously returned null for all checksums (sha1, md5, sha256, sha512, sha1_git) and there was no way to tell an empty file apart from a directory in scan output.

This PR:

  • src/commoncode/hash.py: multi_checksums() now returns the real checksums of empty content for empty files (md5 d41d8cd98f00b204e9800998ecf8427e, sha1 da39a3ee5e6b4b0d3255bfef95601890afd80709, sha256 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, sha512 cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e, sha1_git e69de29bb2d1d6434b8b29ae775ad8c2e48c5391). Non-files still return None.
  • src/scancode/api.py + src/scancode/plugin_info.py: new is_empty file-info flag — true only for real files with size 0; directories are never is_empty.
  • Tests: updated test_checksum_empty_file, added test_multi_checksums_empty_file and test_multi_checksums_empty_file_unknown_algorithm in tests/commoncode/test_hash.py; updated test_get_file_info_include_size in tests/scancode/test_api.py; 41 golden files updated (only is_empty additions and empty-file checksum changes).

Test results (local, PYTHONPATH=src):

  • tests/commoncode/test_hash.py + tests/scancode/test_api.py: 38 passed.
  • tests/licensedcode/ (excluding test_license_db.py, which cannot be collected here — pre-existing distutils removal on Python 3.12): 474 passed, 0 failed.
  • tests/packagedcode/: 25 failures, failure list identical before/after the change (all pre-existing).
  • End-to-end --info smoke scan: empty file → real sha1 + is_empty: true; non-empty file → normal checksums, is_empty: false; directory → is_empty: false.
  • Final re-run of all directly affected test files at committed state: 67 passed.

This branch has not been deployed

No deployments
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.

Always return checksums for all files even if empty, add a new filetype flag is_empty

1 participant