Skip to content

Commit

Permalink
Handle parent diff binary file duplicates.
Browse files Browse the repository at this point in the history
When iterating on a branch involving binary files, it was possible to
hit a case where we would try to upload the source file associated with
a parent diff and hit a conflict. The API returns a DUPLICATE_ITEM error
because we already have a file with that revision, and RBTools would
then crash.

Because of the way file attachment comments work on diffs, it's fine for
us to share the source file attachment for the parent diff across
multiple different diff revisions. We can therefore ignore the duplicate
error.

Testing Done:
Followed the reproduction steps for the bug and saw that before this
change `rbt post` would crash, and after everything worked fine.
Verified that the posted diffs worked as expected.

Reviewed at https://reviews.reviewboard.org/r/14052/
  • Loading branch information
davidt committed Jul 23, 2024
1 parent 5fe507e commit ca1c8ee
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions rbtools/commands/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -1781,11 +1781,20 @@ def _upload_binary_files(
logger.debug('Uploading parent revision for file %s (%s)',
source_filename, source_revision)

self.diff_file_attachments_resource.upload_attachment(
filename=os.path.basename(source_filename),
content=source_file_content,
filediff_id=file.id,
source_file=True)
try:
self.diff_file_attachments_resource.upload_attachment(
filename=os.path.basename(source_filename),
content=source_file_content,
filediff_id=file.id,
source_file=True)
except APIError as e:
if e.http_status == 409 and e.error_code == 111:
logger.debug(
'Attachment for parent revision for file %s '
'(%s) already exists',
source_filename, source_revision)
else:
raise e

def _validate_squashed_diff(self, squashed_diff):
"""Validate the diff to ensure that it can be parsed and files exist.
Expand Down

0 comments on commit ca1c8ee

Please sign in to comment.