diff options
| author | 2010-05-24 01:54:48 +0200 | |
|---|---|---|
| committer | 2010-05-24 01:54:48 +0200 | |
| commit | cf13b6bb3ddaeeed801733f30f093a0f48c5869c (patch) | |
| tree | 5c2052473c785f763341399089c11b68ac3801bf | |
| parent | Check if file is already uploaded on FTP. (diff) | |
| download | AnyLoader-cf13b6bb3ddaeeed801733f30f093a0f48c5869c.tar.xz AnyLoader-cf13b6bb3ddaeeed801733f30f093a0f48c5869c.zip | |
Another QFtp termination race condition.
| -rw-r--r-- | daemon/UploadTask.cpp | 31 | ||||
| -rw-r--r-- | daemon/UploadTask.h | 4 |
2 files changed, 18 insertions, 17 deletions
diff --git a/daemon/UploadTask.cpp b/daemon/UploadTask.cpp index 8f8e816..4af0092 100644 --- a/daemon/UploadTask.cpp +++ b/daemon/UploadTask.cpp @@ -1,18 +1,15 @@ #include "UploadTask.h" +#include "EncodeTarget.h" #include <QDebug> #include <QFile> #include <QFileInfo> -#include <EncodeTarget.h> +#include <QFtp> UploadTask::UploadTask(QObject *parent) : Task(false, parent), - m_ftp(this), + m_ftp(0), m_sizeQuery(0), m_currentFile(0) { - connect(&m_ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SIGNAL(uploadProgress(qint64,qint64))); - connect(&m_ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(storeUploadProgress(qint64,qint64))); - connect(&m_ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(commandFinished(int,bool))); - connect(&m_ftp, SIGNAL(rawCommandReply(int,QString)), this, SLOT(rawCommandReply(int,QString))); } UploadTask::~UploadTask() { @@ -22,12 +19,17 @@ UploadTask::~UploadTask() bool UploadTask::executeTask(Movie *movie) { Q_UNUSED(movie) + m_ftp = new QFtp(this); + connect(m_ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SIGNAL(uploadProgress(qint64,qint64))); + connect(m_ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(storeUploadProgress(qint64,qint64))); + connect(m_ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(commandFinished(int,bool))); + connect(m_ftp, SIGNAL(rawCommandReply(int,QString)), this, SLOT(rawCommandReply(int,QString))); m_currentFile = 0; m_currentFileIndex = 0; m_status.clear(); m_fileUpload = 0; - m_ftp.connectToHost("62.219.1.20"); - m_ftp.login("title_loader", "clip0l0gy"); + m_ftp->connectToHost("62.219.1.20"); + m_ftp->login("title_loader", "clip0l0gy"); queueNext(); return true; } @@ -40,23 +42,22 @@ void UploadTask::queueNext() } m_status.clear(); if (m_currentFileIndex >= currentMovie()->mp4Locations().length()) { - m_ftp.close(); + m_ftp->close(); setCompleted(true); return; } m_currentFile = new QFile(currentMovie()->mp4Locations().at(m_currentFileIndex)); m_status = QString("%1 - Checking for already existing file...").arg(EncodeTarget::targets().at(m_currentFileIndex).name()); - m_sizeQuery = m_ftp.rawCommand(QString("SIZE %1").arg(QFileInfo(m_currentFile->fileName()).fileName())); + m_sizeQuery = m_ftp->rawCommand(QString("SIZE %1").arg(QFileInfo(m_currentFile->fileName()).fileName())); } void UploadTask::rawCommandReply(int replyCode, const QString &detail) { - if (replyCode == 213 && m_ftp.currentId() == m_sizeQuery) { + if (replyCode == 213 && m_ftp->currentId() == m_sizeQuery) { bool success; int size = detail.toLongLong(&success); if (success && m_currentFile->size() == size) { ++m_currentFileIndex; queueNext(); - return; } else commandFinished(m_sizeQuery, true); } @@ -69,7 +70,7 @@ void UploadTask::commandFinished(int id, bool error) { if (error && id == m_sizeQuery) { m_status = QString("%1 - Starting transfer...").arg(EncodeTarget::targets().at(m_currentFileIndex).name()); - m_fileUpload = m_ftp.put(m_currentFile, QFileInfo(m_currentFile->fileName()).fileName(), QFtp::Binary); + m_fileUpload = m_ftp->put(m_currentFile, QFileInfo(m_currentFile->fileName()).fileName(), QFtp::Binary); } else if (error) terminate(); @@ -84,8 +85,8 @@ bool UploadTask::canRunTask(const Movie *movie) const } void UploadTask::kill() { - m_ftp.abort(); - m_ftp.close(); + delete m_ftp; + m_ftp = 0; m_status.clear(); if (m_currentFile) { m_currentFile->close(); diff --git a/daemon/UploadTask.h b/daemon/UploadTask.h index 6317a25..68dcf17 100644 --- a/daemon/UploadTask.h +++ b/daemon/UploadTask.h @@ -2,8 +2,8 @@ #define UPLOADTASK_H #include "Task.h" -#include <QFtp> class QFile; +class QFtp; class UploadTask : public Task { @@ -21,7 +21,7 @@ protected: private: void queueNext(); - QFtp m_ftp; + QFtp *m_ftp; int m_currentFileIndex; QString m_status; int m_fileUpload; |
