Commit c586d011 authored by Joris Guisson's avatar Joris Guisson
Browse files

Changes :

- Merged 652329 from trunk (saveIndexFile exception catching)
- Merged 655548 from trunk (incomplete torrents and scanfolder plugin)
- Upped version to 2.1.4


svn path=/branches/ktorrent/2.1/; revision=656428
parent 508fe9e3
Changes in 2.1.4
- Fixed crash in parsing of DHT messages
- Fixed problem with files with .. in their name
- ScanFolder can now handle incomplete torrent files properly
Changes in 2.1.3
- Fixed crash in torrent parsing
Changes in 2.1.2
- Fix 2 security vulnerabilities (thanks to Bryan Burns from Juniper Networks
for finding them)
......
#MIN_CONFIG(3.3)
AM_INIT_AUTOMAKE(ktorrent,2.1.3)
AM_INIT_AUTOMAKE(ktorrent,2.1.4)
dnl #### Check for FSEEK variants
AC_SYS_LARGEFILE
......
......@@ -27,10 +27,10 @@ namespace kt
{
const bt::Uint32 MAJOR = 2;
const bt::Uint32 MINOR = 1;
const char VERSION_STRING[] = "2.1.3";
const char PEER_ID[] = "-KT2130-";
const char VERSION_STRING[] = "2.1.4";
const char PEER_ID[] = "-KT2140-";
}
#define KT_VERSION_MACRO "2.1.3"
#define KT_VERSION_MACRO "2.1.4"
#endif
......@@ -1014,7 +1014,18 @@ namespace bt
}
}
recalc_chunks_left = true;
saveIndexFile();
try
{
saveIndexFile();
}
catch (bt::Error & err)
{
Out(SYS_DIO|LOG_DEBUG) << "Failed to save index file : " << err.toString() << endl;
}
catch (...)
{
Out(SYS_DIO|LOG_DEBUG) << "Failed to save index file : unkown exception" << endl;
}
chunksLeft();
corrupted_count = 0;
}
......
......@@ -31,7 +31,12 @@
#include <torrent/globals.h>
#include <util/log.h>
#include <util/fileops.h>
#include <util/functions.h>
#include <util/constants.h>
#include <torrent/bnode.h>
#include <torrent/bdecoder.h>
#include <interfaces/coreinterface.h>
......@@ -55,7 +60,7 @@ namespace kt
connect(m_dir, SIGNAL(newItems( const KFileItemList& )), this, SLOT(onNewItems( const KFileItemList& )));
connect(m_core, SIGNAL(loadingFinished( const KURL&, bool, bool )), this, SLOT(onLoadingFinished( const KURL&, bool, bool )));
connect(&m_incomplePollingTimer,SIGNAL(timeout()),this,SLOT(onIncompletePollingTimeout()));
}
......@@ -73,7 +78,7 @@ namespace kt
{
QString name = file->name();
QString dirname = m_dir->url().path();
QString filename = dirname + "/" + name;
QString filename = dirname + bt::DirSeparator() + name;
if(!name.endsWith(".torrent"))
continue;
......@@ -81,7 +86,7 @@ namespace kt
if(name.startsWith("."))
{
//Check if corresponding torrent exists
if(!QFile::exists(m_dir->url().path() + "/" + name.right(name.length() - 1)) && (m_loadedAction == defaultAction))
if(!QFile::exists(m_dir->url().path() + bt::DirSeparator() + name.right(name.length() - 1)) && (m_loadedAction == defaultAction))
QFile::remove(filename);
continue;
......@@ -94,14 +99,30 @@ namespace kt
if(QFile::exists(dirname + "/." + name))
continue;
//Add pending entry...
m_pendingURLs.push_back(source);
//Load torrent
if(m_openSilently)
m_core->loadSilently(source);
if (incomplete(source))
{
// incomplete file, try this again in 10 seconds
bt::Out(SYS_SNF|LOG_NOTICE) << "ScanFolder : incomplete file " << source << endl;
m_incompleteURLs.append(source);
if (m_incompleteURLs.count() == 1)
{
// first URL so start the poll timer
// lets poll every 10 seconds
m_incomplePollingTimer.start(10000,false);
}
}
else
m_core->load(source);
{
bt::Out(SYS_SNF|LOG_NOTICE) << "ScanFolder : found " << source << endl;
//Add pending entry...
m_pendingURLs.push_back(source);
//Load torrent
if(m_openSilently)
m_core->loadSilently(source);
else
m_core->load(source);
}
}
}
......@@ -176,5 +197,77 @@ namespace kt
} else
m_valid = true;
}
bool ScanFolder::incomplete(const KURL & src)
{
// try to decode file, if it is syntactically correct, we can try to load it
QFile fptr(src.path());
if (!fptr.open(IO_ReadOnly))
return false;
try
{
QByteArray data(fptr.size());
fptr.readBlock(data.data(),fptr.size());
bt::BDecoder dec(data,false);
bt::BNode* n = dec.decode();
if (n)
{
// valid node, so file is complete
delete n;
return false;
}
else
{
// decoding failed so incomplete
return true;
}
}
catch (...)
{
// any error means shit happened and the file is incomplete
return true;
}
return false;
}
void ScanFolder::onIncompletePollingTimeout()
{
bt::Out(SYS_SNF|LOG_NOTICE) << "ScanFolder : checking incomplete files" << endl;
for (QValueList<KURL>::iterator i = m_incompleteURLs.begin(); i != m_incompleteURLs.end();)
{
KURL source = *i;
if (!bt::Exists(source.path()))
{
// doesn't exist anymore, so throw out of list
i = m_incompleteURLs.erase(i);
}
else if (!incomplete(source))
{
bt::Out(SYS_SNF|LOG_NOTICE) << "ScanFolder : incomplete file " << source << " appears to be completed " << endl;
//Add pending entry...
m_pendingURLs.push_back(source);
//Load torrent
if(m_openSilently)
m_core->loadSilently(source);
else
m_core->load(source);
// remove from incomplete list
i = m_incompleteURLs.erase(i);
}
else
{
bt::Out(SYS_SNF|LOG_NOTICE) << "ScanFolder : still incomplete : " << source << endl;
i++;
}
}
// stop timer when no incomple URL's are left
if (m_incompleteURLs.count() == 0)
m_incomplePollingTimer.stop();
}
}
#include "scanfolder.moc"
\ No newline at end of file
......@@ -26,6 +26,7 @@
#include <qobject.h>
#include <qdir.h>
#include <qvaluelist.h>
#include <qtimer.h>
#include <kurl.h>
namespace kt
......@@ -86,6 +87,11 @@ namespace kt
public slots:
void onNewItems(const KFileItemList &items);
void onLoadingFinished(const KURL & url,bool success,bool canceled);
void onIncompletePollingTimeout();
private:
/// Check if the URL is a complete file
bool incomplete(const KURL & src);
private:
CoreInterface* m_core;
......@@ -97,7 +103,9 @@ namespace kt
bool m_openSilently;
QValueList<KURL> m_pendingURLs;
QValueList<KURL> m_incompleteURLs;
QTimer m_incomplePollingTimer;
};
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment