Commit 8b728c2b authored by Simon Persson's avatar Simon Persson

Restructure code in BackupJob class and subclasses

Pass in the backup plan and let the jobs read info directly from there. Makes code shorter and more flexible to add or remove settings which are read by backup jobs.
parent 627de08d
......@@ -28,10 +28,8 @@
#include <sys/syscall.h>
#endif
BackupJob::BackupJob(const QStringList &pPathsIncluded, const QStringList &pPathsExcluded,
const QString &pDestinationPath, const QString &pLogFilePath)
:KJob(), mPathsIncluded(pPathsIncluded), mPathsExcluded(pPathsExcluded),
mDestinationPath(pDestinationPath), mLogFilePath(pLogFilePath)
BackupJob::BackupJob(const BackupPlan &pBackupPlan, const QString &pDestinationPath, const QString &pLogFilePath)
:KJob(), mBackupPlan(pBackupPlan), mDestinationPath(pDestinationPath), mLogFilePath(pLogFilePath)
{
mLogFile.setFileName(mLogFilePath);
mLogFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
......
......@@ -39,11 +39,9 @@ public:
};
protected:
BackupJob(const QStringList &pPathsIncluded, const QStringList &pPathsExcluded,
const QString &pDestinationPath, const QString &pLogFilePath);
BackupJob(const BackupPlan &pBackupPlan, const QString &pDestinationPath, const QString &pLogFilePath);
static void makeNice(int pPid);
QStringList mPathsIncluded;
QStringList mPathsExcluded;
const BackupPlan &mBackupPlan;
QString mDestinationPath;
QString mLogFilePath;
QFile mLogFile;
......
......@@ -25,10 +25,8 @@
#include <QDir>
#include <QTimer>
BupJob::BupJob(const QStringList &pPathsIncluded, const QStringList &pPathsExcluded,
const QString &pDestinationPath, const QString &pLogFilePath, bool pGenerateRecoveryInfo)
:BackupJob(pPathsIncluded, pPathsExcluded, pDestinationPath, pLogFilePath),
mGenerateRecoveryInfo(pGenerateRecoveryInfo)
BupJob::BupJob(const BackupPlan &pBackupPlan, const QString &pDestinationPath, const QString &pLogFilePath)
:BackupJob(pBackupPlan, pDestinationPath, pLogFilePath)
{
mIndexProcess.setOutputChannelMode(KProcess::SeparateChannels);
mSaveProcess.setOutputChannelMode(KProcess::SeparateChannels);
......@@ -77,11 +75,11 @@ void BupJob::startIndexing() {
mIndexProcess << QLatin1String("-d") << mDestinationPath;
mIndexProcess << QLatin1String("index") << QLatin1String("-u");
foreach(QString lExclude, mPathsExcluded) {
foreach(QString lExclude, mBackupPlan.mPathsExcluded) {
mIndexProcess << QLatin1String("--exclude");
mIndexProcess << lExclude;
}
mIndexProcess << mPathsIncluded;
mIndexProcess << mBackupPlan.mPathsIncluded;
connect(&mIndexProcess, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(slotIndexingDone(int,QProcess::ExitStatus)));
connect(&mIndexProcess, SIGNAL(started()), SLOT(slotIndexingStarted()));
......@@ -108,7 +106,7 @@ void BupJob::slotIndexingDone(int pExitCode, QProcess::ExitStatus pExitStatus) {
mSaveProcess << QLatin1String("-d") << mDestinationPath;
mSaveProcess << QLatin1String("save");
mSaveProcess << QLatin1String("-n") << QLatin1String("kup");
mSaveProcess << mPathsIncluded;
mSaveProcess << mBackupPlan.mPathsIncluded;
connect(&mSaveProcess, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(slotSavingDone(int,QProcess::ExitStatus)));
connect(&mSaveProcess, SIGNAL(started()), SLOT(slotSavingStarted()));
......@@ -130,7 +128,7 @@ void BupJob::slotSavingDone(int pExitCode, QProcess::ExitStatus pExitStatus) {
emitResult();
return;
}
if(mGenerateRecoveryInfo) {
if(mBackupPlan.mGenerateRecoveryInfo) {
mFsckProcess << QLatin1String("bup");
mFsckProcess << QLatin1String("-d") << mDestinationPath;
mFsckProcess << QLatin1String("fsck");
......
......@@ -30,8 +30,7 @@ class BupJob : public BackupJob
Q_OBJECT
public:
BupJob(const QStringList &pPathsIncluded, const QStringList &pPathsExcluded,
const QString &pDestinationPath, const QString &pLogFilePath, bool pGenerateRecoveryInfo);
BupJob(const BackupPlan &pBackupPlan, const QString &pDestinationPath, const QString &pLogFilePath);
virtual void start();
protected slots:
......@@ -48,7 +47,6 @@ protected:
KProcess mSaveProcess;
KProcess mFsckProcess;
QString mBupVersion;
bool mGenerateRecoveryInfo;
};
#endif /*BUPJOB_H*/
......@@ -269,10 +269,9 @@ void PlanExecutor::showFilesClicked() {
BackupJob *PlanExecutor::createBackupJob() {
if(mPlan->mBackupType == BackupPlan::BupType) {
return new BupJob(mPlan->mPathsIncluded, mPlan->mPathsExcluded, mDestinationPath, mLogFilePath,
mPlan->mGenerateRecoveryInfo);
return new BupJob(*mPlan, mDestinationPath, mLogFilePath);
} else if(mPlan->mBackupType == BackupPlan::RsyncType) {
return new RsyncJob(mPlan->mPathsIncluded, mPlan->mPathsExcluded, mDestinationPath, mLogFilePath);
return new RsyncJob(*mPlan, mDestinationPath, mLogFilePath);
}
qWarning("Invalid backup type in configuration!");
return NULL;
......
......@@ -24,9 +24,8 @@
#include <KLocale>
#include <QTimer>
RsyncJob::RsyncJob(const QStringList &pPathsIncluded, const QStringList &pPathsExcluded,
const QString &pDestinationPath, const QString &pLogFilePath)
:BackupJob(pPathsIncluded, pPathsExcluded, pDestinationPath, pLogFilePath)
RsyncJob::RsyncJob(const BackupPlan &pBackupPlan, const QString &pDestinationPath, const QString &pLogFilePath)
:BackupJob(pBackupPlan, pDestinationPath, pLogFilePath)
{
mRsyncProcess.setOutputChannelMode(KProcess::SeparateChannels);
}
......@@ -54,10 +53,10 @@ void RsyncJob::startRsync() {
mRsyncProcess << QLatin1String("rsync") << QLatin1String("-aR");
mRsyncProcess << QLatin1String("--delete") << QLatin1String("--delete-excluded");
foreach(QString lExclude, mPathsExcluded) {
foreach(QString lExclude, mBackupPlan.mPathsExcluded) {
mRsyncProcess << QString::fromLatin1("--exclude=%1").arg(lExclude);
}
mRsyncProcess << mPathsIncluded;
mRsyncProcess << mBackupPlan.mPathsIncluded;
mRsyncProcess << mDestinationPath;
connect(&mRsyncProcess, SIGNAL(started()), SLOT(slotRsyncStarted()));
......
......@@ -30,8 +30,7 @@ class RsyncJob : public BackupJob
Q_OBJECT
public:
RsyncJob(const QStringList &pPathsIncluded, const QStringList &pPathsExcluded,
const QString &pDestinationPath, const QString &pLogFilePath);
RsyncJob(const BackupPlan &pBackupPlan, const QString &pDestinationPath, const QString &pLogFilePath);
virtual void start();
......
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