Use copyjobs KAuth helper for other copying jobs too.
This commit is contained in:
parent
61fed73a5d
commit
bf2a23dada
|
@ -63,11 +63,8 @@ bool BackupFileSystemJob::run(Report& parent)
|
|||
report->line() << xi18nc("@info:progress", "Could not open file system on source partition <filename>%1</filename> for backup.", sourcePartition().deviceNode());
|
||||
else if (!copyTarget.open())
|
||||
report->line() << xi18nc("@info:progress", "Could not create backup file <filename>%1</filename>.", fileName());
|
||||
else {
|
||||
ExternalCommand copyCmd(copySource, copyTarget, QProcess::SeparateChannels);
|
||||
connect(©Cmd, &ExternalCommand::progress, this, [=] (int percent) { emit progress(percent); }, Qt::QueuedConnection);
|
||||
rval = copyCmd.startCopyBlocks(-1);
|
||||
}
|
||||
else
|
||||
rval = copyBlocks(*report, copyTarget, copySource);
|
||||
}
|
||||
|
||||
jobFinished(*report, rval);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "core/copysourcedevice.h"
|
||||
#include "core/copytargetdevice.h"
|
||||
|
||||
#include "util/externalcommand.h"
|
||||
#include "util/report.h"
|
||||
|
||||
#include <QIcon>
|
||||
|
@ -38,70 +39,10 @@ Job::Job() :
|
|||
|
||||
bool Job::copyBlocks(Report& report, CopyTarget& target, CopySource& source)
|
||||
{
|
||||
bool rval = true;
|
||||
const qint64 blockSize = 10 * 1024 * 1024; // number of bytes per block to copy
|
||||
const qint64 blocksToCopy = source.length() / blockSize;
|
||||
|
||||
qint64 readOffset = source.firstByte();
|
||||
qint64 writeOffset = target.firstByte();
|
||||
qint32 copyDirection = 1;
|
||||
|
||||
if (target.firstByte() > source.firstByte()) {
|
||||
readOffset = source.firstByte() + source.length() - blockSize;
|
||||
writeOffset = target.firstByte() + source.length() - blockSize;
|
||||
copyDirection = -1;
|
||||
}
|
||||
|
||||
report.line() << xi18nc("@info:progress", "Copying %1 blocks (%2 bytes) from %3 to %4, direction: %5.", blocksToCopy, source.length(), readOffset, writeOffset, copyDirection == 1 ? i18nc("direction: left", "left") : i18nc("direction: right", "right"));
|
||||
|
||||
qint64 blocksCopied = 0;
|
||||
|
||||
QByteArray buffer;
|
||||
int percent = 0;
|
||||
QTime t;
|
||||
t.start();
|
||||
while (blocksCopied < blocksToCopy) {
|
||||
if (!(rval = source.readData(buffer, readOffset + blockSize * blocksCopied * copyDirection, blockSize)))
|
||||
break;
|
||||
|
||||
if (!(rval = target.writeData(buffer, writeOffset + blockSize * blocksCopied * copyDirection)))
|
||||
break;
|
||||
|
||||
if (++blocksCopied * 100 / blocksToCopy != percent) {
|
||||
percent = blocksCopied * 100 / blocksToCopy;
|
||||
|
||||
if (percent % 5 == 0 && t.elapsed() > 1000) {
|
||||
const qint64 mibsPerSec = (blocksCopied * blockSize / 1024 / 1024) / (t.elapsed() / 1000);
|
||||
const qint64 estSecsLeft = (100 - percent) * t.elapsed() / percent / 1000;
|
||||
report.line() << xi18nc("@info:progress", "Copying %1 MiB/second, estimated time left: %2", mibsPerSec, QTime(0, 0).addSecs(estSecsLeft).toString());
|
||||
}
|
||||
emit progress(percent);
|
||||
}
|
||||
}
|
||||
const qint64 lastBlock = source.length() % blockSize;
|
||||
|
||||
// copy the remainder
|
||||
if (rval && lastBlock > 0) {
|
||||
Q_ASSERT(lastBlock < blockSize);
|
||||
|
||||
const qint64 lastBlockReadOffset = copyDirection > 0 ? readOffset + blockSize * blocksCopied : source.firstByte();
|
||||
const qint64 lastBlockWriteOffset = copyDirection > 0 ? writeOffset + blockSize * blocksCopied : target.firstByte();
|
||||
|
||||
report.line() << xi18nc("@info:progress", "Copying remainder of block size %1 from %2 to %3.", lastBlock, lastBlockReadOffset, lastBlockWriteOffset);
|
||||
|
||||
rval = source.readData(buffer, lastBlockReadOffset, lastBlock);
|
||||
|
||||
if (rval)
|
||||
rval = target.writeData(buffer, lastBlockWriteOffset);
|
||||
|
||||
if (rval)
|
||||
emit progress(100);
|
||||
}
|
||||
|
||||
|
||||
report.line() << xi18ncp("@info:progress argument 2 is a string such as 7 bytes (localized accordingly)", "Copying 1 block (%2) finished.", "Copying %1 blocks (%2) finished.", blocksCopied, i18np("1 byte", "%1 bytes", target.bytesWritten()));
|
||||
|
||||
return rval;
|
||||
// FIXME: report
|
||||
ExternalCommand copyCmd(source, target, QProcess::SeparateChannels);
|
||||
connect(©Cmd, &ExternalCommand::progress, this, &Job::progress, Qt::QueuedConnection);
|
||||
return copyCmd.startCopyBlocks(-1);
|
||||
}
|
||||
|
||||
bool Job::rollbackCopyBlocks(Report& report, CopyTarget& origTarget, CopySource& origSource)
|
||||
|
|
Loading…
Reference in New Issue