Rename source/targetFirstByte to source/targetOffset.
Add some diagrams explaining difference between source/targetOffsets and read/writeOffset.
This commit is contained in:
parent
ee0a1e1b41
commit
d34b617272
|
@ -153,7 +153,7 @@ bool ExternalCommandHelper::CreateFile(const QString &filePath, const QByteArray
|
||||||
}
|
}
|
||||||
|
|
||||||
// If targetDevice is empty then return QByteArray with data that was read from disk.
|
// If targetDevice is empty then return QByteArray with data that was read from disk.
|
||||||
QVariantMap ExternalCommandHelper::CopyBlocks(const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize)
|
QVariantMap ExternalCommandHelper::CopyBlocks(const QString& sourceDevice, const qint64 sourceOffset, const qint64 sourceLength, const QString& targetDevice, const qint64 targetOffset, const qint64 blockSize)
|
||||||
{
|
{
|
||||||
if (!isCallerAuthorized()) {
|
if (!isCallerAuthorized()) {
|
||||||
return QVariantMap();
|
return QVariantMap();
|
||||||
|
@ -186,18 +186,24 @@ QVariantMap ExternalCommandHelper::CopyBlocks(const QString& sourceDevice, const
|
||||||
Left = 1,
|
Left = 1,
|
||||||
Right = -1,
|
Right = -1,
|
||||||
};
|
};
|
||||||
|
qint8 copyDirection = targetOffset > sourceOffset ? CopyDirection::Right : CopyDirection::Left;
|
||||||
|
|
||||||
const qint64 blocksToCopy = sourceLength / blockSize;
|
// Let readOffset (r) and writeOffset (w) be the offsets of the first block that we move.
|
||||||
qint64 readOffset = sourceFirstByte;
|
// When we move data to the left:
|
||||||
qint64 writeOffset = targetFirstByte;
|
// ______target______ ______source______
|
||||||
qint8 copyDirection = CopyDirection::Left;
|
// r <- w=================
|
||||||
|
qint64 readOffset = sourceOffset;
|
||||||
|
qint64 writeOffset = targetOffset;
|
||||||
|
|
||||||
if (targetFirstByte > sourceFirstByte) {
|
// When we move data to the right, we start moving data from the last block
|
||||||
readOffset = sourceFirstByte + sourceLength - blockSize;
|
// ______source______ ______target______
|
||||||
writeOffset = targetFirstByte + sourceLength - blockSize;
|
// =================r -> w
|
||||||
copyDirection = CopyDirection::Right;
|
if (copyDirection == CopyDirection::Right) {
|
||||||
|
readOffset = sourceOffset + sourceLength - blockSize;
|
||||||
|
writeOffset = targetOffset + sourceLength - blockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const qint64 blocksToCopy = sourceLength / blockSize;
|
||||||
const qint64 lastBlock = sourceLength % blockSize;
|
const qint64 lastBlock = sourceLength % blockSize;
|
||||||
|
|
||||||
qint64 bytesWritten = 0;
|
qint64 bytesWritten = 0;
|
||||||
|
@ -242,8 +248,8 @@ QVariantMap ExternalCommandHelper::CopyBlocks(const QString& sourceDevice, const
|
||||||
if (rval && lastBlock > 0) {
|
if (rval && lastBlock > 0) {
|
||||||
Q_ASSERT(lastBlock < blockSize);
|
Q_ASSERT(lastBlock < blockSize);
|
||||||
|
|
||||||
const qint64 lastBlockReadOffset = copyDirection == CopyDirection::Left ? readOffset + blockSize * blocksCopied : sourceFirstByte;
|
const qint64 lastBlockReadOffset = copyDirection == CopyDirection::Left ? readOffset + blockSize * blocksCopied : sourceOffset;
|
||||||
const qint64 lastBlockWriteOffset = copyDirection == CopyDirection::Left ? writeOffset + blockSize * blocksCopied : targetFirstByte;
|
const qint64 lastBlockWriteOffset = copyDirection == CopyDirection::Left ? writeOffset + blockSize * blocksCopied : targetOffset;
|
||||||
reportText = xi18nc("@info:progress", "Copying remainder of block size %1 from %2 to %3.", lastBlock, lastBlockReadOffset, lastBlockWriteOffset);
|
reportText = xi18nc("@info:progress", "Copying remainder of block size %1 from %2 to %3.", lastBlock, lastBlockReadOffset, lastBlockWriteOffset);
|
||||||
Q_EMIT report(reportText);
|
Q_EMIT report(reportText);
|
||||||
rval = readData(sourceDevice, buffer, lastBlockReadOffset, lastBlock);
|
rval = readData(sourceDevice, buffer, lastBlockReadOffset, lastBlock);
|
||||||
|
|
Loading…
Reference in New Issue