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

Clarify generate_targets_metadata() #1033

Closed

Conversation

joshuagl
Copy link
Member

@joshuagl joshuagl commented May 20, 2020

Fixes issue #: N/A

Description of the changes being introduced by the pull request:

  • Improve documentation for generate_targets_metadata(), in the docstring and code comments, to make the use_existing_fileinfo and write_consistent_targets arguments, and their interactions, clearer.
  • Fix generate_targets_metadata() so that both use_existing_fileinfo and write_consistent_fileinfo can be used together, as required by Warehouse for PEP 458

Please verify and check that the pull request fulfills the following
requirements
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

Clarify, through the docstrings and code comments, the expected behaviour
of generate_targets_metadata() and the interactions of the
use_existing_fileinfo and write_consistent_targets parameters.

Signed-off-by: Joshua Lock <jlock@vmware.com>
It should be possible to request consistent targets metadata when using
existing fileinfo, because the metadata itself doesn't differ. Consistent
targets, copies of the file with the file's hash prepended to the target's
file name, should exist in the targets directory but are not listed in the
targets metadata.

Throwing an exception here prevents enabling consistent metadata to be
written when using existing fileinfo structures, instead we log that the
consistent copies of the target files are expected to exist in the
repository's targets directory and continue assuming they are present.

Signed-off-by: Joshua Lock <jlock@vmware.com>
for target, fileinfo in six.iteritems(target_files):

# Ensure all fileinfo entries in target_files have a non-empty hashes dict
if not fileinfo.get('hashes', None):
raise securesystemslib.exceptions.Error('use_existing_hashes option set'
' but no hashes exist in roledb for ' + repr(target))

if fileinfo.get('length', -1) < 0:
# and a non-empty, non-zero, length
if fileinfo.get('length', -1) < 1:
Copy link
Member Author

Choose a reason for hiding this comment

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

I think it doesn't make sense to have zero length targets files, but maybe this should be restored to the prior check of: if len < 0 ?

Copy link
Member

Choose a reason for hiding this comment

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

I think it doesn't make sense to have zero length targets files, but maybe this should be restored to the prior check of: if len < 0 ?

@joshuagl, the classical __init__.py file is a good example for a target file with zero length.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, thanks for pointing out that case @lukpueh. In which case I should restore this to the prior if len < 0. Will force push a fix later today.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I already restored the behaviour for checking len < 0 in #1034, which contains an updated version of this change. Apologies for the confusion.

Copy link
Member

Choose a reason for hiding this comment

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

No need to apologize. I have no business commenting on closed PRs. :D

@joshuagl joshuagl requested a review from mnm678 May 20, 2020 14:21
Copy link
Contributor

@mnm678 mnm678 left a comment

Choose a reason for hiding this comment

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

It looks like setting both write_consistent_targets and use_existing_fileinfo just ignores the write_consistent_targets, which I'm not sure would be the expected behavior. If the caller is responsible for writing the consistent files, it might make more sense for them to set write_consistent_targets to false here, then write the consistent files afterwards. But I might be misunderstanding the goal.

@@ -1240,9 +1251,12 @@ def generate_targets_metadata(targets_directory, target_files, version,
securesystemslib.formats.BOOLEAN_SCHEMA.check_match(write_consistent_targets)
securesystemslib.formats.BOOLEAN_SCHEMA.check_match(use_existing_fileinfo)

# If the caller requested consistent targets *and* supplied their own fileinfo
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# If the caller requested consistent targets *and* supplied their own fileinfo
# If the caller requested consistent targets *and* supplied their own fileinfo,

@joshuagl
Copy link
Member Author

@lukpueh already resolved this issue at the right level by modifying _generate_and_write_metadata() to call generate_targets_metadats() with an appropriate value for write_consistent_targets based on the values of consistent_snapshot and use_existing_fileinfo in b9891e1

Apologies for the noise. I will close this PR and include the first patch in a later PR.

@joshuagl joshuagl closed this May 20, 2020
@joshuagl joshuagl deleted the joshuagl/generate-targets branch May 20, 2020 21:08
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.

None yet

3 participants