File: planexecutor.cpp

package info (click to toggle)
kup-backup 0.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,576 kB
  • sloc: cpp: 8,422; xml: 311; makefile: 6; sh: 3
file content (549 lines) | stat: -rw-r--r-- 20,998 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
// SPDX-FileCopyrightText: 2020 Simon Persson <simon.persson@mykolab.com>
//
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL

#include "planexecutor.h"
#include "bupjob.h"
#include "buprepairjob.h"
#include "bupverificationjob.h"
#include "kupdaemon.h"
#include "kupdaemon_debug.h"
#include "rsyncjob.h"

#include <KFormat>
#include <KIO/DirectorySizeJob>
#include <KIO/OpenUrlJob>
#include <KLocalizedString>
#include <KNotification>
#include <QDBusConnection>
#include <QDBusReply>
#include <QDir>
#include <QStorageInfo>
#include <QTimer>

static const QString cPwrMgmtServiceName = QStringLiteral("org.freedesktop.PowerManagement");
static const QString cPwrMgmtPath = QStringLiteral("/org/freedesktop/PowerManagement");
static const QString cPwrMgmtInhibitInterface = QStringLiteral("org.freedesktop.PowerManagement.Inhibit");
static const QString cPwrMgmtInterface = QStringLiteral("org.freedesktop.PowerManagement");

PlanExecutor::PlanExecutor(BackupPlan *pPlan, KupDaemon *pKupDaemon)
    : QObject(pKupDaemon)
    , mState(NOT_AVAILABLE)
    , mPlan(pPlan)
    , mQuestion(nullptr)
    , mFailNotification(nullptr)
    , mIntegrityNotification(nullptr)
    , mRepairNotification(nullptr)
    , mLastState(NOT_AVAILABLE)
    , mKupDaemon(pKupDaemon)
    , mSleepCookie(0)
{
    QString lCachePath = QString::fromLocal8Bit(qgetenv("XDG_CACHE_HOME").constData());
    if (lCachePath.isEmpty()) {
        lCachePath = QDir::homePath();
        lCachePath.append(QStringLiteral("/.cache"));
    }
    lCachePath.append(QStringLiteral("/kup"));
    QDir lCacheDir(lCachePath);
    if (!lCacheDir.exists()) {
        if (!lCacheDir.mkpath(lCachePath)) {
            lCachePath = QStringLiteral("/tmp");
        }
    }
    mLogFilePath = lCachePath;
    mLogFilePath.append(QStringLiteral("/kup_plan"));
    mLogFilePath.append(QString::number(mPlan->planNumber()));
    mLogFilePath.append(QStringLiteral(".log"));

    mSchedulingTimer = new QTimer(this);
    mSchedulingTimer->setSingleShot(true);
    connect(mSchedulingTimer, SIGNAL(timeout()), SLOT(enterAvailableState()));
}

PlanExecutor::~PlanExecutor() = default;

QString PlanExecutor::currentActivityTitle()
{
    switch (mState) {
    case BACKUP_RUNNING:
        return i18nc("status in tooltip", "Saving backup");
    case INTEGRITY_TESTING:
        return i18nc("status in tooltip", "Checking backup integrity");
    case REPAIRING:
        return i18nc("status in tooltip", "Repairing backups");
    default:;
    }

    switch (mPlan->backupStatus()) {
    case BackupPlan::GOOD:
        return i18nc("status in tooltip", "Backup status OK");
    case BackupPlan::MEDIUM:
        return i18nc("status in tooltip", "New backup suggested");
    case BackupPlan::BAD:
        return i18nc("status in tooltip", "New backup needed");
    default:;
    }
    return QString();
}

// dispatcher code for entering one of the available states
void PlanExecutor::enterAvailableState()
{
    if (mState == NOT_AVAILABLE) {
        mState = WAITING_FOR_FIRST_BACKUP; // initial child state of "Available" state
        emit stateChanged();
    }
    QDateTime lNow = QDateTime::currentDateTimeUtc();
    switch (mPlan->mScheduleType) {
    case BackupPlan::MANUAL:
        break;
    case BackupPlan::INTERVAL: {
        QDateTime lNextTime = mPlan->nextScheduledTime();
        if (!lNextTime.isValid() || lNextTime < lNow) {
            if (!mPlan->mLastCompleteBackup.isValid())
                askUserOrStart(xi18nc("@info", "Do you want to save a first backup now?"));
            else {
                QString t = KFormat().formatSpelloutDuration(static_cast<quint64>(mPlan->mLastCompleteBackup.secsTo(lNow)) * 1000);
                askUserOrStart(xi18nc("@info",
                                      "It has been %1 since last backup was saved.\n"
                                      "Save a new backup now?",
                                      t));
            }
        } else {
            // Call this method again in five minutes to check if it's time.
            // The alternative of sleeping all the way to when backup saving is due
            // has the problem that time spent suspended is not counted.
            mSchedulingTimer->start(5 * 60 * 1000);
        }
        break;
    }
    case BackupPlan::USAGE:
        if (!mPlan->mLastCompleteBackup.isValid()) {
            askUserOrStart(xi18nc("@info", "Do you want to save a first backup now?"));
        } else if (mPlan->mAccumulatedUsageTime > static_cast<quint32>(mPlan->mUsageLimit) * 3600) {
            QString t = KFormat().formatSpelloutDuration(mPlan->mAccumulatedUsageTime * 1000);
            askUserOrStart(xi18nc("@info",
                                  "You have been active for %1 since last backup was saved.\n"
                                  "Save a new backup now?",
                                  t));
        }
        break;
    }
}

void PlanExecutor::askUserOrStart(const QString &pUserQuestion)
{
    // Only ask the first time after destination has become available.
    // Always ask if power saving is active.
    if ((mPlan->mAskBeforeTakingBackup && mState == WAITING_FOR_FIRST_BACKUP) || powerSaveActive()) {
        askUser(pUserQuestion);
    } else {
        startBackupSaveJob();
    }
}

void PlanExecutor::enterNotAvailableState()
{
    discardUserQuestion();
    mSchedulingTimer->stop();
    mState = NOT_AVAILABLE;
    emit stateChanged();
}

void PlanExecutor::askUser(const QString &pQuestion)
{
    discardUserQuestion();
    mQuestion = new KNotification(QStringLiteral("StartBackup"), KNotification::Persistent);
    mQuestion->setTitle(mPlan->mDescription);
    mQuestion->setText(pQuestion);

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QStringList lAnswers;
    lAnswers << xi18nc("@action:button", "Yes") << xi18nc("@action:button", "No");
    mQuestion->setActions(lAnswers);
    connect(mQuestion, SIGNAL(action1Activated()), SLOT(startBackupSaveJob()));
    connect(mQuestion, SIGNAL(action2Activated()), SLOT(discardUserQuestion()));
#else
    KNotificationAction *yes = mQuestion->addAction(xi18nc("@action:button", "Yes"));
    connect(yes, &KNotificationAction::activated, this, &PlanExecutor::startBackupSaveJob);

    KNotificationAction *no = mQuestion->addAction(xi18nc("@action:button", "No"));
    connect(no, &KNotificationAction::activated, this, &PlanExecutor::discardUserQuestion);
#endif
    connect(mQuestion, SIGNAL(closed()), SLOT(discardUserQuestion()));
    connect(mQuestion, SIGNAL(ignored()), SLOT(discardUserQuestion()));
    // enter this "do nothing" state, if user answers "no" or ignores, remain there
    mState = WAITING_FOR_MANUAL_BACKUP;
    emit stateChanged();
    mQuestion->sendEvent();
}

void PlanExecutor::discardUserQuestion()
{
    if (mQuestion) {
        mQuestion->deleteLater();
        mQuestion = nullptr;
    }
}

void PlanExecutor::notifyBackupFailed(KJob *pFailedJob)
{
    discardFailNotification();
    mFailNotification = new KNotification(QStringLiteral("BackupFailed"), KNotification::Persistent);
    mFailNotification->setTitle(xi18nc("@title:window", "Saving of Backup Failed"));
    mFailNotification->setText(pFailedJob->errorText());

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QStringList lAnswers;
    if (pFailedJob->error() == BackupJob::ErrorWithLog) {
        lAnswers << xi18nc("@action:button", "Show log file");
        connect(mFailNotification, SIGNAL(action1Activated()), SLOT(showLog()));
    } else if (pFailedJob->error() == BackupJob::ErrorSuggestRepair) {
        lAnswers << xi18nc("@action:button", "Yes");
        lAnswers << xi18nc("@action:button", "No");
        connect(mFailNotification, SIGNAL(action1Activated()), SLOT(startRepairJob()));
    } else if (pFailedJob->error() == BackupJob::ErrorSourcesConfig) {
        lAnswers << xi18nc("@action:button", "Open settings");
        connect(mFailNotification, &KNotification::action1Activated, this, [this] {
            QProcess::startDetached(QStringLiteral("kcmshell5"),
                                    {QStringLiteral("--args"), QStringLiteral("show_sources %1").arg(mPlan->planNumber()), QStringLiteral("kcm_kup")});
        });
    }
    mFailNotification->setActions(lAnswers);

    connect(mFailNotification, SIGNAL(action2Activated()), SLOT(discardFailNotification()));
#else
    if (pFailedJob->error() == BackupJob::ErrorWithLog) {
        KNotificationAction *showLogFile = mFailNotification->addAction(xi18nc("@action:button", "Show log file"));
        connect(showLogFile, &KNotificationAction::activated, this, &PlanExecutor::showLog);
    } else if (pFailedJob->error() == BackupJob::ErrorSuggestRepair) {
        KNotificationAction *yes = mFailNotification->addAction(xi18nc("@action:button", "Yes"));
        connect(yes, &KNotificationAction::activated, this, &PlanExecutor::startRepairJob);

        KNotificationAction *no = mFailNotification->addAction(xi18nc("@action:button", "No"));
        connect(no, &KNotificationAction::activated, this, &PlanExecutor::discardFailNotification);
    } else if (pFailedJob->error() == BackupJob::ErrorSourcesConfig) {
        KNotificationAction *openSettings = mFailNotification->addAction(xi18nc("@action:button", "Open settings"));
        connect(openSettings, &KNotificationAction::activated, this, [this] {
            QProcess::startDetached(QStringLiteral("kcmshell5"),
                                    {QStringLiteral("--args"), QStringLiteral("show_sources %1").arg(mPlan->planNumber()), QStringLiteral("kcm_kup")});
        });
    }
#endif
    connect(mFailNotification, SIGNAL(closed()), SLOT(discardFailNotification()));
    connect(mFailNotification, SIGNAL(ignored()), SLOT(discardFailNotification()));
    mFailNotification->sendEvent();
}

void PlanExecutor::discardFailNotification()
{
    if (mFailNotification) {
        mFailNotification->deleteLater();
        mFailNotification = nullptr;
    }
}

void PlanExecutor::notifyBackupSucceeded()
{
    auto *lNotification = new KNotification(QStringLiteral("BackupSucceeded"));
    lNotification->setTitle(xi18nc("@title:window", "Backup Saved"));
    lNotification->setText(xi18nc("@info notification", "Saving backup completed successfully."));
    lNotification->sendEvent();
}

void PlanExecutor::showLog()
{
    auto *job = new KIO::OpenUrlJob(QUrl::fromLocalFile(mLogFilePath), QStringLiteral("text/x-log"));
    job->start();
}

void PlanExecutor::startIntegrityCheck()
{
    if (mPlan->mBackupType != BackupPlan::BupType || busy() || !destinationAvailable()) {
        return;
    }
    KJob *lJob = new BupVerificationJob(*mPlan, mDestinationPath, mLogFilePath, mKupDaemon);
    connect(lJob, &KJob::result, this, &PlanExecutor::integrityCheckFinished);
    lJob->start();
    mLastState = mState;
    mState = INTEGRITY_TESTING;
    emit stateChanged();
    startSleepInhibit();
}

void PlanExecutor::startRepairJob()
{
    if (mPlan->mBackupType != BackupPlan::BupType || busy() || !destinationAvailable()) {
        return;
    }
    KJob *lJob = new BupRepairJob(*mPlan, mDestinationPath, mLogFilePath, mKupDaemon);
    connect(lJob, &KJob::result, this, &PlanExecutor::repairFinished);
    lJob->start();
    mLastState = mState;
    mState = REPAIRING;
    emit stateChanged();
    startSleepInhibit();
}

void PlanExecutor::startBackupSaveJob()
{
    if (busy() || !destinationAvailable()) {
        return;
    }
    discardUserQuestion();
    mState = BACKUP_RUNNING;
    emit stateChanged();
    startSleepInhibit();
    startBackup();
}

void PlanExecutor::startBackup()
{
    QFileInfo lInfo(mDestinationPath);
    if (!lInfo.isWritable()) {
        KNotification::event(KNotification::Error,
                             xi18nc("@title:window", "Problem"),
                             xi18nc("notification", "You don't have write permission to backup destination."));
        exitBackupRunningState(false);
        return;
    }
    BackupJob *lJob = createBackupJob();
    if (lJob == nullptr) {
        KNotification::event(KNotification::Error, xi18nc("@title:window", "Problem"), xi18nc("notification", "Invalid type of backup in configuration."));
        exitBackupRunningState(false);
        return;
    }
    connect(lJob, &KJob::result, this, &PlanExecutor::finishBackup);
    lJob->start();
}

void PlanExecutor::finishBackup(KJob *pJob)
{
    if (pJob->error()) {
        if (pJob->error() != KJob::KilledJobError) {
            notifyBackupFailed(pJob);
        }
        exitBackupRunningState(false);
    } else {
        notifyBackupSucceeded();
        mPlan->mLastCompleteBackup = QDateTime::currentDateTimeUtc();
        QStorageInfo storageInfo(mDestinationPath);
        if (storageInfo.isValid())
            mPlan->mLastAvailableSpace = static_cast<double>(storageInfo.bytesAvailable());
        else
            mPlan->mLastAvailableSpace = -1.0; // unknown size

        auto lSizeJob = KIO::directorySize(QUrl::fromLocalFile(mDestinationPath));
        connect(lSizeJob, &KJob::result, this, &PlanExecutor::finishSizeCheck);
        lSizeJob->start();
    }
}

void PlanExecutor::finishSizeCheck(KJob *pJob)
{
    if (pJob->error()) {
        KNotification::event(KNotification::Error, xi18nc("@title:window", "Problem"), pJob->errorText());
        mPlan->mLastBackupSize = -1.0; // unknown size
    } else {
        auto lSizeJob = qobject_cast<KIO::DirectorySizeJob *>(pJob);
        mPlan->mLastBackupSize = static_cast<double>(lSizeJob->totalSize());
    }
    mPlan->save();
    exitBackupRunningState(pJob->error() == 0);
}

void PlanExecutor::integrityCheckFinished(KJob *pJob)
{
    endSleepInhibit();
    discardIntegrityNotification();
    mIntegrityNotification = new KNotification(QStringLiteral("IntegrityCheckCompleted"), KNotification::Persistent);
    mIntegrityNotification->setTitle(xi18nc("@title:window", "Integrity Check Completed"));
    mIntegrityNotification->setText(pJob->errorText());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QStringList lAnswers;
    if (pJob->error() == BackupJob::ErrorWithLog) {
        lAnswers << xi18nc("@action:button", "Show log file");
        connect(mIntegrityNotification, SIGNAL(action1Activated()), SLOT(showLog()));
    } else if (pJob->error() == BackupJob::ErrorSuggestRepair) {
        lAnswers << xi18nc("@action:button", "Yes");
        lAnswers << xi18nc("@action:button", "No");
        connect(mIntegrityNotification, SIGNAL(action1Activated()), SLOT(startRepairJob()));
    }
    mIntegrityNotification->setActions(lAnswers);

    connect(mIntegrityNotification, SIGNAL(action2Activated()), SLOT(discardIntegrityNotification()));
#else
    if (pJob->error() == BackupJob::ErrorWithLog) {
        KNotificationAction *showLogFile = new KNotificationAction(xi18nc("@action:button", "Show log file"));
        connect(showLogFile, &KNotificationAction::activated, this, &PlanExecutor::showLog);
    } else if (pJob->error() == BackupJob::ErrorSuggestRepair) {
        KNotificationAction *yes = mIntegrityNotification->addAction(xi18nc("@action:button", "Yes"));
        connect(yes, &KNotificationAction::activated, this, &PlanExecutor::startRepairJob);

        KNotificationAction *no = mIntegrityNotification->addAction(xi18nc("@action:button", "No"));
        connect(no, &KNotificationAction::activated, this, &PlanExecutor::discardIntegrityNotification);
    }
#endif

    connect(mIntegrityNotification, SIGNAL(closed()), SLOT(discardIntegrityNotification()));
    connect(mIntegrityNotification, SIGNAL(ignored()), SLOT(discardIntegrityNotification()));
    mIntegrityNotification->sendEvent();

    if (mState == INTEGRITY_TESTING) { // only restore if nothing has changed during the run
        mState = mLastState;
    }
    emit stateChanged();
}

void PlanExecutor::discardIntegrityNotification()
{
    if (mIntegrityNotification) {
        mIntegrityNotification->deleteLater();
        mIntegrityNotification = nullptr;
    }
}

void PlanExecutor::repairFinished(KJob *pJob)
{
    endSleepInhibit();
    discardRepairNotification();
    mRepairNotification = new KNotification(QStringLiteral("RepairCompleted"), KNotification::Persistent);
    mRepairNotification->setTitle(xi18nc("@title:window", "Repair Completed"));
    mRepairNotification->setText(pJob->errorText());
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QStringList lAnswers;
    lAnswers << xi18nc("@action:button", "Show log file");
    mRepairNotification->setActions(lAnswers);
    connect(mRepairNotification, SIGNAL(action1Activated()), SLOT(showLog()));
#else
    KNotificationAction *showLogFile = mRepairNotification->addAction(xi18nc("@action:button", "Show log file"));
    connect(showLogFile, &KNotificationAction::activated, this, &PlanExecutor::showLog);
#endif
    connect(mRepairNotification, SIGNAL(closed()), SLOT(discardRepairNotification()));
    connect(mRepairNotification, SIGNAL(ignored()), SLOT(discardRepairNotification()));
    mRepairNotification->sendEvent();

    if (mState == REPAIRING) { // only restore if nothing has changed during the run
        mState = mLastState;
    }
    emit stateChanged();
}

void PlanExecutor::discardRepairNotification()
{
    if (mRepairNotification) {
        mRepairNotification->deleteLater();
        mRepairNotification = nullptr;
    }
}

void PlanExecutor::startSleepInhibit()
{
    if (mSleepCookie != 0) {
        return;
    }
    QDBusMessage lMsg = QDBusMessage::createMethodCall(cPwrMgmtServiceName, cPwrMgmtPath, cPwrMgmtInhibitInterface, QStringLiteral("Inhibit"));
    lMsg << i18n("Kup Backup System");
    lMsg << currentActivityTitle();
    QDBusReply<uint> lReply = QDBusConnection::sessionBus().call(lMsg);
    mSleepCookie = lReply.value();
}

void PlanExecutor::endSleepInhibit()
{
    if (mSleepCookie == 0) {
        return;
    }
    QDBusMessage lMsg = QDBusMessage::createMethodCall(cPwrMgmtServiceName, cPwrMgmtPath, cPwrMgmtInhibitInterface, QStringLiteral("UnInhibit"));
    lMsg << mSleepCookie;
    QDBusConnection::sessionBus().asyncCall(lMsg);
    mSleepCookie = 0;
}

void PlanExecutor::exitBackupRunningState(bool pWasSuccessful)
{
    endSleepInhibit();
    if (pWasSuccessful) {
        if (mPlan->mScheduleType == BackupPlan::USAGE) {
            // reset usage time after successful backup
            mPlan->mAccumulatedUsageTime = 0;
            mPlan->save();
        }
        mState = WAITING_FOR_BACKUP_AGAIN;
        emit stateChanged();

        // don't know if status actually changed, potentially did... so trigger a re-read of status
        emit backupStatusChanged();

        // re-enter the main "available" state dispatcher
        enterAvailableState();
    } else {
        mState = WAITING_FOR_MANUAL_BACKUP;
        emit stateChanged();
    }
}

void PlanExecutor::updateAccumulatedUsageTime()
{
    if (mState == BACKUP_RUNNING) { // usage time during backup doesn't count...
        return;
    }

    if (mPlan->mScheduleType == BackupPlan::USAGE) {
        mPlan->mAccumulatedUsageTime += KUP_USAGE_MONITOR_INTERVAL_S;
        mPlan->save();
    }

    // trigger refresh of backup status, potentially changed since some time has passed...
    // this is the reason why this slot is called repeatedly even when
    // not in BackupPlan::USAGE mode
    emit backupStatusChanged();

    // if we're waiting to run backup again, check if it is time now.
    if (mPlan->mScheduleType == BackupPlan::USAGE && (mState == WAITING_FOR_FIRST_BACKUP || mState == WAITING_FOR_BACKUP_AGAIN)) {
        enterAvailableState();
    }
}

void PlanExecutor::showBackupFiles()
{
    if (mState == NOT_AVAILABLE)
        return;
    if (mPlan->mBackupType == BackupPlan::BupType) {
        QStringList lArgs;
        lArgs << mDestinationPath;
        KProcess::startDetached(QStringLiteral("kup-filedigger"), lArgs);
    } else if (mPlan->mBackupType == BackupPlan::RsyncType) {
        auto *job = new KIO::OpenUrlJob(QUrl::fromLocalFile(mDestinationPath));
        job->start();
    }
}

void PlanExecutor::showBackupPurger()
{
    if (mPlan->mBackupType != BackupPlan::BupType || busy() || !destinationAvailable()) {
        return;
    }
    QStringList lArgs;
    lArgs << mDestinationPath;
    KProcess::startDetached(QStringLiteral("kup-purger"), lArgs);
}

BackupJob *PlanExecutor::createBackupJob()
{
    if (mPlan->mBackupType == BackupPlan::BupType) {
        return new BupJob(*mPlan, mDestinationPath, mLogFilePath, mKupDaemon);
    }
    if (mPlan->mBackupType == BackupPlan::RsyncType) {
        return new RsyncJob(*mPlan, mDestinationPath, mLogFilePath, mKupDaemon);
    }
    qCWarning(KUPDAEMON) << "Invalid backup type in configuration!";
    return nullptr;
}

bool PlanExecutor::powerSaveActive()
{
    QDBusMessage lMsg = QDBusMessage::createMethodCall(cPwrMgmtServiceName, cPwrMgmtPath, cPwrMgmtInterface, QStringLiteral("GetPowerSaveStatus"));
    QDBusReply<bool> lReply = QDBusConnection::sessionBus().call(lMsg);
    return lReply.value();
}