diff --git a/lbrynet/daemon/Publisher.py b/lbrynet/daemon/Publisher.py index 645ef5875..c1354fd91 100644 --- a/lbrynet/daemon/Publisher.py +++ b/lbrynet/daemon/Publisher.py @@ -40,6 +40,18 @@ class Publisher(object): claim_dict['stream']['source']['contentType'] = get_content_type(file_path) claim_dict['stream']['source']['version'] = "_0_0_1" # need current version here claim_out = yield self.make_claim(name, bid, claim_dict, claim_address, change_address) + + # check if we have a file already for this claim (if this is a publish update with a new stream) + old_stream_hashes = yield self.session.storage.get_stream_hashes_for_claim_id(claim_out['claim_id']) + if old_stream_hashes: + lbry_files = list(self.lbry_file_manager.lbry_files) + for lbry_file in lbry_files: + s_h = lbry_file.stream_hash + if s_h in old_stream_hashes: + yield self.lbry_file_manager.delete_lbry_file(lbry_file, delete_file=False) + old_stream_hashes.remove(s_h) + log.info("Removed old stream for claim update: %s", s_h) + yield self.session.storage.save_content_claim( self.lbry_file.stream_hash, "%s:%i" % (claim_out['txid'], claim_out['nout']) ) diff --git a/lbrynet/database/storage.py b/lbrynet/database/storage.py index ed6b663a3..86b44ee63 100644 --- a/lbrynet/database/storage.py +++ b/lbrynet/database/storage.py @@ -543,6 +543,14 @@ class SQLiteStorage(object): # support info yield self.save_supports(claim_id, claim_info['supports']) + def get_stream_hashes_for_claim_id(self, claim_id): + return self.run_and_return_list( + "select f.stream_hash from file f " + "inner join content_claim cc on f.stream_hash=cc.stream_hash " + "inner join claim c on c.claim_outpoint=cc.claim_outpoint and c.claim_id=?", + claim_id + ) + def save_content_claim(self, stream_hash, claim_outpoint): def _save_content_claim(transaction): # get the claim id and serialized metadata diff --git a/lbrynet/tests/unit/database/test_SQLiteStorage.py b/lbrynet/tests/unit/database/test_SQLiteStorage.py index 72bb72b79..6288fdcf2 100644 --- a/lbrynet/tests/unit/database/test_SQLiteStorage.py +++ b/lbrynet/tests/unit/database/test_SQLiteStorage.py @@ -296,6 +296,9 @@ class ContentClaimStorageTests(StorageTest): stored_content_claim = yield self.storage.get_content_claim(stream_hash) self.assertDictEqual(stored_content_claim, fake_claim_info) + stream_hashes = yield self.storage.get_stream_hashes_for_claim_id(fake_claim_info['claim_id']) + self.assertListEqual(stream_hashes, [stream_hash]) + # test that we can't associate a claim update with a new stream to the file second_stream_hash, second_sd_hash = random_lbry_hash(), random_lbry_hash() yield self.make_and_store_fake_stream(blob_count=2, stream_hash=second_stream_hash, sd_hash=second_sd_hash)