Merge pull request #3279 from quay/fix-torrent-info-bug

Fix NPE bug in torrentinfo set call
This commit is contained in:
Joseph Schorr 2018-10-31 11:33:11 -04:00 committed by GitHub
commit a048ff3633
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

@ -338,10 +338,14 @@ def get_storage_locations(uuid):
def save_torrent_info(storage_object, piece_length, pieces):
try:
return TorrentInfo.create(storage=storage_object, piece_length=piece_length, pieces=pieces)
except IntegrityError:
# TorrentInfo already exists for this storage.
pass
return TorrentInfo.get(storage=storage_object, piece_length=piece_length)
except TorrentInfo.DoesNotExist:
try:
return TorrentInfo.create(storage=storage_object, piece_length=piece_length, pieces=pieces)
except IntegrityError:
# TorrentInfo already exists for this storage.
return TorrentInfo.get(storage=storage_object, piece_length=piece_length)
def get_torrent_info(blob):
try:

View file

@ -564,6 +564,10 @@ def test_torrent_info(pre_oci_model):
assert pre_oci_model.get_torrent_info(layers[0].blob) is None
pre_oci_model.set_torrent_info(layers[0].blob, 2, 'foo')
# Set it again exactly, which should be a no-op.
pre_oci_model.set_torrent_info(layers[0].blob, 2, 'foo')
# Check the information we've set.
torrent_info = pre_oci_model.get_torrent_info(layers[0].blob)
assert torrent_info is not None
assert torrent_info.piece_length == 2