Fix broken info hash after torrent edit.

This commit is contained in:
2024-09-04 19:16:37 +00:00
parent 4e20380a95
commit 702f95b384
2 changed files with 24 additions and 8 deletions

View File

@@ -145,6 +145,29 @@ public class MetaInfo
this.info_hash = calculateInfoHash();
}
public MetaInfo(MetaInfo old, String new_announce, List<List<String>> new_announce_list, String new_comment, String new_created_by)
{
this.announce = new_announce;
this.info_hash = old.info_hash;
this.name = old.name;
this.name_utf8 = old.name_utf8;
this.files = old.files;
this.files_utf8 = old.files_utf8;
this.attributes = old.attributes;
this.lengths = old.lengths;
this.piece_length = old.piece_length;
this.piece_hashes = old.piece_hashes;
this.length = old.length;
this.privateTorrent = old.privateTorrent;
this.announce_list = new_announce_list;
this.comment = new_comment;
this.created_by = new_created_by;
this.creation_date = old.creation_date;
this.url_list = old.url_list;
this.infoMap = old.infoMap;
this.infoBytesLength = old.infoBytesLength;
}
/**
* Creates a new MetaInfo from the given InputStream. The
* InputStream must start with a correctly bencoded dictionary

View File

@@ -4886,14 +4886,7 @@ public class I2PSnarkServlet extends BasicServlet {
newComment = null;
if (newCreatedBy.equals(""))
newCreatedBy = null;
MetaInfo newMeta = new MetaInfo(thePrimary, meta.getName(), null, meta.getFiles(), meta.getLengths(),
meta.getPieceLength(0), meta.getPieceHashes(), meta.getTotalLength(), meta.getPrivateTrackerStatus(),
newAnnList, newCreatedBy, meta.getWebSeedURLs(), newComment);
if (!DataHelper.eq(meta.getInfoHash(), newMeta.getInfoHash())) {
// shouldn't happen
_manager.addMessage("Torrent edit failed, infohash mismatch");
return;
}
MetaInfo newMeta = new MetaInfo(meta, thePrimary, newAnnList, newComment, newCreatedBy);
File f = new File(_manager.util().getTempDir(), "edit-" + _manager.util().getContext().random().nextLong() + ".torrent");
OutputStream out = null;
try {