piuparts.py: Prevent KeyError in diff_meta_data

Since commit c3900457 different dicts were used for iterating and modifying, so we never modify the dicts we are currently iterating over. However, the commit was incomplete because it was longer guaranteed that each key is still part of the dict we are trying to modify, but no checks were added. The result are possible crashes such as the one reported in 968842:

Traceback (most recent call last):
  File "/usr/sbin/piuparts", line 3267, in <module>
    main()
  File "/usr/sbin/piuparts", line 3252, in main
    process_packages(package_list)
  File "/usr/sbin/piuparts", line 3173, in process_packages
    if not install_purge_test(chroot, chroot_state,
  File "/usr/sbin/piuparts", line 2414, in install_purge_test
    return check_results(chroot, chroot_state, file_owners, deps_info=deps_info)
  File "/usr/sbin/piuparts", line 2235, in check_results
    (new, removed, modified) = diff_meta_data(reference_info, current_info)
  File "/usr/sbin/piuparts", line 2041, in diff_meta_data
    del tree2_c[name]
KeyError: '/var/spool/news/in.coming/tmp/'

Such KeyErrors can be prevented by checking if a key exists in the dict before trying to drop it. Adding explicit checks is simpler than adding a try..except clause here because there are already if clauses that we can adapt.

Closes: #968842

Merge request reports

Loading