Added 'simulate mode' checkbox. It disables archive creation (and compression too), tar overhead not counted therefore. But for estimation purposes it's still acceptable, I think.
If `simulateMode' set to true, `archive' object not even created, so I inserted checking of flag on almost every `archive' use, just to make absense of null-pointer dereference more obvious. diff -ur kbackup-0.7-orig/src/Archiver.cxx kbackup-0.7-mod/src/Archiver.cxx --- kbackup-0.7-orig/src/Archiver.cxx 2010-06-19 13:59:57.000000000 +0400 +++ kbackup-0.7-mod/src/Archiver.cxx 2011-01-23 21:40:29.000000000 +0300 @@ -62,7 +62,7 @@ Archiver::Archiver(QWidget *parent) : QObject(parent), archive(0), totalBytes(0), totalFiles(0), filteredFiles(0), sliceNum(0), mediaNeedsChange(false), - fullBackupInterval(1), incrementalBackup(false), forceFullBackup(false), + fullBackupInterval(1), incrementalBackup(false), forceFullBackup(false), simulateMode(false), sliceCapacity(MAX_SLICE), interactive(parent != 0), cancelled(false), runs(false), skippedFiles(false), verbose(false), jobResult(0) { @@ -166,6 +166,13 @@ //-------------------------------------------------------------------------------- +void Archiver::setSimulateMode(bool sm) +{ + simulateMode = sm; +} + +//-------------------------------------------------------------------------------- + void Archiver::setIncrementalBackup(bool inc) { incrementalBackup = inc; @@ -381,14 +388,17 @@ } // non-interactive mode only allows local targets as KIO needs $DISPLAY - if ( !targetURL.isValid() || (!interactive && !targetURL.isLocalFile()) ) + if ( !simulateMode ) { - emit warning(i18n("The target dir is not valid")); - return false; + if ( !targetURL.isValid() || (!interactive && !targetURL.isLocalFile()) ) + { + emit warning(i18n("The target dir is not valid")); + return false; + } } // check if the target dir exists and optionally create it - if ( targetURL.isLocalFile() ) + if ( !simulateMode && targetURL.isLocalFile() ) { QDir dir(targetURL.path()); if ( !dir.exists() ) @@ -480,7 +490,7 @@ finishSlice(); // reduce the number of old backups to the defined number - if ( !cancelled && (numKeptBackups != UNLIMITED) ) + if ( !simulateMode && !cancelled && (numKeptBackups != UNLIMITED) ) { emit logging(i18n("...reducing number of kept archives to max. %1").arg(numKeptBackups)); @@ -578,7 +588,7 @@ if ( !cancelled ) { lastBackup = startTime; - if ( !isIncrementalBackup() ) + if ( !simulateMode && !isIncrementalBackup() ) { lastFullBackup = lastBackup; setIncrementalBackup(fullBackupInterval > 1); // after a full backup, the next will be incremental @@ -677,9 +687,9 @@ if ( ! cancelled ) { - runScript("slice_closed"); + if ( !simulateMode ) runScript("slice_closed"); - if ( targetURL.isLocalFile() ) + if ( targetURL.isLocalFile() || simulateMode ) { emit logging(i18n("...finished slice %1").arg(archiveName)); sliceList << archiveName; // store name for display at the end @@ -745,7 +755,7 @@ } } - if ( ! cancelled ) + if ( ! cancelled && !simulateMode ) runScript("slice_finished"); if ( !targetURL.isLocalFile() ) @@ -874,14 +884,14 @@ else archiveName += ".tar"; - runScript("slice_init"); + if ( !simulateMode) runScript("slice_init"); calculateCapacity(); // don't create a bz2 compressed file as we compress each file on its own - archive = new KTar(archiveName, "application/x-tar"); + if ( !simulateMode ) archive = new KTar(archiveName, "application/x-tar"); - while ( (sliceCapacity < 1024) || !archive->open(QIODevice::WriteOnly) ) // disk full ? + while ( (sliceCapacity < 1024) || (!simulateMode && !archive->open(QIODevice::WriteOnly)) ) // disk full ? { if ( !interactive ) emit warning(i18n("The file '%1' can not be opened for writing.").arg(archiveName)); @@ -891,7 +901,7 @@ i18n("The file '%1' can not be opened for writing.\n\n" "Do you want to retry?").arg(archiveName)) == KMessageBox::No) ) { - delete archive; + if ( archive ) delete archive; archive = 0; cancel(); @@ -938,7 +948,8 @@ qApp->processEvents(QEventLoop::AllEvents, 5); if ( cancelled ) return; - if ( ! archive->writeDir(QString(".") + dir.absolutePath(), dirInfo.owner(), dirInfo.group(), + if ( ! simulateMode && + ! archive->writeDir(QString(".") + dir.absolutePath(), dirInfo.owner(), dirInfo.group(), status.st_mode, status.st_atime, status.st_mtime, status.st_ctime) ) { emit warning(i18n("Could not write directory '%1' to archive.\n" @@ -1017,13 +1028,14 @@ if ( info.isSymLink() ) { - archive->addLocalFile(info.absoluteFilePath(), QString(".") + info.absoluteFilePath()); + if ( !simulateMode ) + archive->addLocalFile(info.absoluteFilePath(), QString(".") + info.absoluteFilePath()); totalFiles++; emit totalFilesChanged(totalFiles); return; } - if ( !getCompressFiles() ) + if ( !getCompressFiles() || simulateMode ) { if ( ! addLocalFile(info) ) // this also increases totalBytes { @@ -1063,7 +1075,8 @@ return; } - if ( ! archive->prepareWriting(QString(".") + info.absoluteFilePath() + ext, + if ( ! simulateMode && + ! archive->prepareWriting(QString(".") + info.absoluteFilePath() + ext, info.owner(), info.group(), tmpFile.size(), status.st_mode, status.st_atime, status.st_mtime, status.st_ctime) ) { @@ -1076,7 +1089,7 @@ static char buffer[BUFFER_SIZE]; qint64 len; int count = 0; - while ( ! tmpFile.atEnd() ) + while ( ! tmpFile.atEnd() && ! simulateMode ) { len = tmpFile.read(buffer, BUFFER_SIZE); @@ -1090,7 +1103,8 @@ return; } - if ( ! archive->writeData(buffer, len) ) + if ( ! simulateMode && + ! archive->writeData(buffer, len) ) { emit warning(i18n("Could not write to archive. Maybe the medium is full.")); cancel(); @@ -1104,7 +1118,8 @@ if ( cancelled ) return; } } - if ( ! archive->finishWriting(tmpFile.size()) ) + if ( ! simulateMode && + ! archive->finishWriting(tmpFile.size()) ) { emit warning(i18n("Could not write to archive. Maybe the medium is full.")); cancel(); @@ -1113,8 +1128,15 @@ } // get filesize - sliceBytes = archive->device()->pos(); // account for tar overhead totalBytes += tmpFile.size(); + if ( !simulateMode ) + { + sliceBytes = archive->device()->pos(); // account for tar overhead + } + else + { + sliceBytes = totalBytes; // simulate mode have no way to estimate overhead + } emit sliceProgress(static_cast<int>(sliceBytes * 100 / sliceCapacity)); } @@ -1153,7 +1175,8 @@ if ( (sliceBytes + sourceStat.st_size) > sliceCapacity ) if ( ! getNextSlice() ) return false; - if ( ! archive->prepareWriting(QString(".") + info.absoluteFilePath(), + if ( ! simulateMode && + ! archive->prepareWriting(QString(".") + info.absoluteFilePath(), info.owner(), info.group(), sourceStat.st_size, sourceStat.st_mode, sourceStat.st_atime, sourceStat.st_mtime, sourceStat.st_ctime) ) { @@ -1171,7 +1194,7 @@ KIO::filesize_t fileSize = sourceStat.st_size; KIO::filesize_t written = 0; - while ( fileSize && !sourceFile.atEnd() && !cancelled ) + while ( !simulateMode && fileSize && !sourceFile.atEnd() && !cancelled ) { len = sourceFile.read(buffer, BUFFER_SIZE); @@ -1184,7 +1207,8 @@ return false; } - if ( ! archive->writeData(buffer, len) ) + if ( ! simulateMode && + ! archive->writeData(buffer, len) ) { emit warning(i18n("Could not write to archive. Maybe the medium is full.")); return false; @@ -1218,13 +1242,26 @@ msgShown = true; } } + + if ( simulateMode ) + { + totalBytes += fileSize; // have to update totalBytes because other increment masked + } + emit fileProgress(100); sourceFile.close(); if ( !cancelled ) { // get filesize - sliceBytes = archive->device()->pos(); // account for tar overhead + if ( !simulateMode ) + { + sliceBytes = archive->device()->pos(); // account for tar overhead + } + else + { + sliceBytes = totalBytes; // simulate mode have no way to estimate overhead + } emit sliceProgress(static_cast<int>(sliceBytes * 100 / sliceCapacity)); } @@ -1232,7 +1269,7 @@ if ( msgShown && interactive ) QApplication::restoreOverrideCursor(); - if ( !cancelled && !archive->finishWriting(sourceStat.st_size) ) + if ( !cancelled && !simulateMode && !archive->finishWriting(sourceStat.st_size) ) { emit warning(i18n("Could not write to archive. Maybe the medium is full.")); return false; diff -ur kbackup-0.7-orig/src/Archiver.hxx kbackup-0.7-mod/src/Archiver.hxx --- kbackup-0.7-orig/src/Archiver.hxx 2010-06-19 13:59:57.000000000 +0400 +++ kbackup-0.7-mod/src/Archiver.hxx 2011-01-23 21:39:52.000000000 +0300 @@ -101,6 +101,7 @@ public slots: void cancel(); // cancel a running creation void setForceFullBackup(bool force = true); + void setSimulateMode(bool sm); signals: void inProgress(bool runs); @@ -176,6 +177,7 @@ int fullBackupInterval; bool incrementalBackup; bool forceFullBackup; + bool simulateMode; KIO::filesize_t sliceBytes; KIO::filesize_t sliceCapacity; diff -ur kbackup-0.7-orig/src/MainWidgetBase.ui kbackup-0.7-mod/src/MainWidgetBase.ui --- kbackup-0.7-orig/src/MainWidgetBase.ui 2010-06-18 00:52:27.000000000 +0400 +++ kbackup-0.7-mod/src/MainWidgetBase.ui 2011-01-23 20:51:21.000000000 +0300 @@ -109,7 +109,7 @@ </item> </layout> </item> - <item row="2" column="0"> + <item row="3" column="0"> <widget class="Q3GroupBox" name="groupBox3"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> @@ -224,7 +224,7 @@ </layout> </widget> </item> - <item row="3" column="0"> + <item row="4" column="0"> <widget class="Q3GroupBox" name="groupBox2"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> @@ -352,7 +352,7 @@ </layout> </widget> </item> - <item row="4" column="0"> + <item row="5" column="0"> <layout class="QVBoxLayout"> <item> <widget class="QTextEdit" name="log"> @@ -493,6 +493,13 @@ </item> </layout> </item> + <item row="2" column="0"> + <widget class="QCheckBox" name="simulateMode"> + <property name="text"> + <string>Simulate mode</string> + </property> + </widget> + </item> </layout> </widget> <layoutdefault spacing="6" margin="11"/> diff -ur kbackup-0.7-orig/src/MainWidget.cxx kbackup-0.7-mod/src/MainWidget.cxx --- kbackup-0.7-orig/src/MainWidget.cxx 2010-06-18 00:52:27.000000000 +0400 +++ kbackup-0.7-mod/src/MainWidget.cxx 2011-01-23 21:59:37.000000000 +0300 @@ -37,6 +37,7 @@ connect(ui.cancelButton, SIGNAL(clicked()), Archiver::instance, SLOT(cancel())); connect(ui.forceFullBackup, SIGNAL(clicked(bool)), Archiver::instance, SLOT(setForceFullBackup(bool))); + connect(ui.simulateMode, SIGNAL(clicked(bool)), Archiver::instance, SLOT(setSimulateMode(bool))); connect(Archiver::instance, SIGNAL(logging(const QString &)), ui.log, SLOT(append(const QString &))); connect(Archiver::instance, SIGNAL(warning(const QString &)), ui.warnings, SLOT(append(const QString &))); -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org