forked from I2P_Developers/i2p.i2p
i2psnark:
- Rename bad .torrent files instead of deleting them - Add mime type for .xz
This commit is contained in:
@ -1242,30 +1242,34 @@ public class SnarkManager implements CompleteListener {
|
|||||||
}
|
}
|
||||||
String rejectMessage = validateTorrent(info);
|
String rejectMessage = validateTorrent(info);
|
||||||
if (rejectMessage != null) {
|
if (rejectMessage != null) {
|
||||||
sfile.delete();
|
throw new IOException(rejectMessage);
|
||||||
addMessage(rejectMessage);
|
}
|
||||||
return;
|
|
||||||
} else {
|
// TODO load saved closest DHT nodes and pass to the Snark ?
|
||||||
// TODO load saved closest DHT nodes and pass to the Snark ?
|
// This may take a LONG time
|
||||||
// This may take a LONG time
|
if (baseFile == null)
|
||||||
if (baseFile == null)
|
baseFile = getSavedBaseFile(info.getInfoHash());
|
||||||
baseFile = getSavedBaseFile(info.getInfoHash());
|
if (_log.shouldLog(Log.INFO))
|
||||||
if (_log.shouldLog(Log.INFO))
|
_log.info("New Snark, torrent: " + filename + " base: " + baseFile);
|
||||||
_log.info("New Snark, torrent: " + filename + " base: " + baseFile);
|
torrent = new Snark(_util, filename, null, -1, null, null, this,
|
||||||
torrent = new Snark(_util, filename, null, -1, null, null, this,
|
_peerCoordinatorSet, _connectionAcceptor,
|
||||||
_peerCoordinatorSet, _connectionAcceptor,
|
shouldAutoStart(), dataDir.getPath(), baseFile);
|
||||||
shouldAutoStart(), dataDir.getPath(), baseFile);
|
loadSavedFilePriorities(torrent);
|
||||||
loadSavedFilePriorities(torrent);
|
synchronized (_snarks) {
|
||||||
synchronized (_snarks) {
|
_snarks.put(filename, torrent);
|
||||||
_snarks.put(filename, torrent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
String err = _("Torrent in \"{0}\" is invalid", sfile.getName()) + ": " + ioe.getMessage();
|
String err = _("Torrent in \"{0}\" is invalid", sfile.toString()) + ": " + ioe.getMessage();
|
||||||
addMessage(err);
|
addMessage(err);
|
||||||
_log.error(err, ioe);
|
_log.error(err, ioe);
|
||||||
if (sfile.exists())
|
File rename = new File(filename + ".BAD");
|
||||||
sfile.delete();
|
if (rename.exists()) {
|
||||||
|
if (sfile.delete())
|
||||||
|
addMessage(_("Torrent file deleted: {0}", sfile.toString()));
|
||||||
|
} else {
|
||||||
|
if (FileUtil.rename(sfile, rename))
|
||||||
|
addMessage(_("Torrent file moved from {0} to {1}", sfile.toString(), rename.toString()));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} catch (OutOfMemoryError oom) {
|
} catch (OutOfMemoryError oom) {
|
||||||
addMessage(_("ERROR - Out of memory, cannot create torrent from {0}", sfile.getName()) + ": " + oom.getMessage());
|
addMessage(_("ERROR - Out of memory, cannot create torrent from {0}", sfile.getName()) + ": " + oom.getMessage());
|
||||||
@ -1895,18 +1899,18 @@ public class SnarkManager implements CompleteListener {
|
|||||||
private String validateTorrent(MetaInfo info) {
|
private String validateTorrent(MetaInfo info) {
|
||||||
List<List<String>> files = info.getFiles();
|
List<List<String>> files = info.getFiles();
|
||||||
if ( (files != null) && (files.size() > MAX_FILES_PER_TORRENT) ) {
|
if ( (files != null) && (files.size() > MAX_FILES_PER_TORRENT) ) {
|
||||||
return _("Too many files in \"{0}\" ({1}), deleting it!", info.getName(), files.size());
|
return _("Too many files in \"{0}\" ({1})!", info.getName(), files.size());
|
||||||
} else if ( (files == null) && (info.getName().endsWith(".torrent")) ) {
|
} else if ( (files == null) && (info.getName().endsWith(".torrent")) ) {
|
||||||
return _("Torrent file \"{0}\" cannot end in \".torrent\", deleting it!", info.getName());
|
return _("Torrent file \"{0}\" cannot end in \".torrent\"!", info.getName());
|
||||||
} else if (info.getPieces() <= 0) {
|
} else if (info.getPieces() <= 0) {
|
||||||
return _("No pieces in \"{0}\", deleting it!", info.getName());
|
return _("No pieces in \"{0}\"!", info.getName());
|
||||||
} else if (info.getPieces() > Storage.MAX_PIECES) {
|
} else if (info.getPieces() > Storage.MAX_PIECES) {
|
||||||
return _("Too many pieces in \"{0}\", limit is {1}, deleting it!", info.getName(), Storage.MAX_PIECES);
|
return _("Too many pieces in \"{0}\", limit is {1}!", info.getName(), Storage.MAX_PIECES);
|
||||||
} else if (info.getPieceLength(0) > Storage.MAX_PIECE_SIZE) {
|
} else if (info.getPieceLength(0) > Storage.MAX_PIECE_SIZE) {
|
||||||
return _("Pieces are too large in \"{0}\" ({1}B), deleting it.", info.getName(), DataHelper.formatSize2(info.getPieceLength(0))) + ' ' +
|
return _("Pieces are too large in \"{0}\" ({1}B)!", info.getName(), DataHelper.formatSize2(info.getPieceLength(0))) + ' ' +
|
||||||
_("Limit is {0}B", DataHelper.formatSize2(Storage.MAX_PIECE_SIZE));
|
_("Limit is {0}B", DataHelper.formatSize2(Storage.MAX_PIECE_SIZE));
|
||||||
} else if (info.getTotalLength() <= 0) {
|
} else if (info.getTotalLength() <= 0) {
|
||||||
return _("Torrent \"{0}\" has no data, deleting it!", info.getName());
|
return _("Torrent \"{0}\" has no data!", info.getName());
|
||||||
} else if (info.getTotalLength() > Storage.MAX_TOTAL_SIZE) {
|
} else if (info.getTotalLength() > Storage.MAX_TOTAL_SIZE) {
|
||||||
System.out.println("torrent info: " + info.toString());
|
System.out.println("torrent info: " + info.toString());
|
||||||
List<Long> lengths = info.getLengths();
|
List<Long> lengths = info.getLengths();
|
||||||
@ -1914,7 +1918,7 @@ public class SnarkManager implements CompleteListener {
|
|||||||
for (int i = 0; i < lengths.size(); i++)
|
for (int i = 0; i < lengths.size(); i++)
|
||||||
System.out.println("File " + i + " is " + lengths.get(i) + " long.");
|
System.out.println("File " + i + " is " + lengths.get(i) + " long.");
|
||||||
|
|
||||||
return _("Torrents larger than {0}B are not supported yet, deleting \"{1}\"", Storage.MAX_TOTAL_SIZE, info.getName());
|
return _("Torrents larger than {0}B are not supported yet \"{1}\"!", Storage.MAX_TOTAL_SIZE, info.getName());
|
||||||
} else {
|
} else {
|
||||||
// ok
|
// ok
|
||||||
return null;
|
return null;
|
||||||
|
@ -3274,7 +3274,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
icon = "itoopie_xxsm";
|
icon = "itoopie_xxsm";
|
||||||
else
|
else
|
||||||
icon = "compress";
|
icon = "compress";
|
||||||
} else if (mime.equals("application/x-gtar") ||
|
} else if (mime.equals("application/x-gtar") || mime.equals("application/x-xz") ||
|
||||||
mime.equals("application/compress") || mime.equals("application/gzip") ||
|
mime.equals("application/compress") || mime.equals("application/gzip") ||
|
||||||
mime.equals("application/x-7z-compressed") || mime.equals("application/x-rar-compressed") ||
|
mime.equals("application/x-7z-compressed") || mime.equals("application/x-rar-compressed") ||
|
||||||
mime.equals("application/x-tar") || mime.equals("application/x-bzip2"))
|
mime.equals("application/x-tar") || mime.equals("application/x-bzip2"))
|
||||||
|
@ -31,3 +31,4 @@ war = application/java-archive
|
|||||||
webm = video/webm
|
webm = video/webm
|
||||||
wma = audio/x-ms-wma
|
wma = audio/x-ms-wma
|
||||||
wmv = video/x-ms-wmv
|
wmv = video/x-ms-wmv
|
||||||
|
xz = application/x-xz
|
||||||
|
Reference in New Issue
Block a user