Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
System
KPMCore
Commits
27b85117
Commit
27b85117
authored
Feb 20, 2022
by
Andrius Štikonas
Browse files
Rename blockSize to chunkSize to avoid confusion with physical blocks.
parent
d9ceb502
Pipeline
#140154
passed with stage
in 1 minute and 57 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/util/externalcommandhelper.cpp
View file @
27b85117
...
...
@@ -156,19 +156,19 @@ bool ExternalCommandHelper::CreateFile(const QString &filePath, const QByteArray
}
// If targetDevice is empty then return QByteArray with data that was read from disk.
QVariantMap
ExternalCommandHelper
::
CopyFileData
(
const
QString
&
sourceDevice
,
const
qint64
sourceOffset
,
const
qint64
sourceLength
,
const
QString
&
targetDevice
,
const
qint64
targetOffset
,
const
qint64
bloc
kSize
)
QVariantMap
ExternalCommandHelper
::
CopyFileData
(
const
QString
&
sourceDevice
,
const
qint64
sourceOffset
,
const
qint64
sourceLength
,
const
QString
&
targetDevice
,
const
qint64
targetOffset
,
const
qint64
chun
kSize
)
{
if
(
!
isCallerAuthorized
())
{
return
{};
}
// Avoid division by zero further down
if
(
!
bloc
kSize
)
{
if
(
!
chun
kSize
)
{
return
{};
}
// Prevent some out of memory situations
if
(
bloc
kSize
>
100
*
MiB
)
{
if
(
chun
kSize
>
100
*
MiB
)
{
return
{};
}
...
...
@@ -187,13 +187,13 @@ QVariantMap ExternalCommandHelper::CopyFileData(const QString& sourceDevice, con
QVariantMap
reply
;
reply
[
QStringLiteral
(
"success"
)]
=
true
;
// This enum specified whether individual
bloc
ks are moved left or right
// This enum specified whether individual
data chun
ks are moved left or right
// When source and target devices are the same we have to be careful not to overwrite
// source data with newly written data. We don't have to do this if sourceDevice is not
// targetDevice but there are no disadvantages in applying the same scheme.
// When partition is moved to the left, we start with the leftmost
bloc
k,
// and move it further left, then second leftmost
bloc
k and so on.
// But when we move partition to the right, we start with rightmost
bloc
k.
// When partition is moved to the left, we start with the leftmost
chun
k,
// and move it further left, then second leftmost
chun
k and so on.
// But when we move partition to the right, we start with rightmost
chun
k.
// To account for this difference, we introduce CopyDirection variable which takes
// care of some of the differences in offset calculation between these two cases.
enum
CopyDirection
:
qint8
{
...
...
@@ -202,26 +202,26 @@ QVariantMap ExternalCommandHelper::CopyFileData(const QString& sourceDevice, con
};
qint8
copyDirection
=
targetOffset
>
sourceOffset
?
CopyDirection
::
Right
:
CopyDirection
::
Left
;
// Let readOffset (r) and writeOffset (w) be the offsets of the first
bloc
k that we move.
// Let readOffset (r) and writeOffset (w) be the offsets of the first
chun
k that we move.
// When we move data to the left:
// ______target______ ______source______
// r <- w=================
qint64
readOffset
=
sourceOffset
;
qint64
writeOffset
=
targetOffset
;
// When we move data to the right, we start moving data from the last
bloc
k
// When we move data to the right, we start moving data from the last
chun
k
// ______source______ ______target______
// =================r -> w
if
(
copyDirection
==
CopyDirection
::
Right
)
{
readOffset
=
sourceOffset
+
sourceLength
-
bloc
kSize
;
writeOffset
=
targetOffset
+
sourceLength
-
bloc
kSize
;
readOffset
=
sourceOffset
+
sourceLength
-
chun
kSize
;
writeOffset
=
targetOffset
+
sourceLength
-
chun
kSize
;
}
const
qint64
bloc
ksToCopy
=
sourceLength
/
bloc
kSize
;
const
qint64
lastBlock
=
sourceLength
%
bloc
kSize
;
const
qint64
chun
ksToCopy
=
sourceLength
/
chun
kSize
;
const
qint64
lastBlock
=
sourceLength
%
chun
kSize
;
qint64
bytesWritten
=
0
;
qint64
bloc
ksCopied
=
0
;
qint64
chun
ksCopied
=
0
;
QByteArray
buffer
;
int
percent
=
0
;
...
...
@@ -229,7 +229,7 @@ QVariantMap ExternalCommandHelper::CopyFileData(const QString& sourceDevice, con
timer
.
start
();
QString
reportText
=
xi18nc
(
"@info:progress"
,
"Copying %1
bloc
ks (%2 bytes) from %3 to %4, direction: %5."
,
bloc
ksToCopy
,
QString
reportText
=
xi18nc
(
"@info:progress"
,
"Copying %1
chun
ks (%2 bytes) from %3 to %4, direction: %5."
,
chun
ksToCopy
,
sourceLength
,
readOffset
,
writeOffset
,
copyDirection
==
CopyDirection
::
Left
?
i18nc
(
"direction: left"
,
"left"
)
:
i18nc
(
"direction: right"
,
"right"
));
Q_EMIT
report
(
reportText
);
...
...
@@ -238,20 +238,20 @@ QVariantMap ExternalCommandHelper::CopyFileData(const QString& sourceDevice, con
QFile
target
(
targetDevice
);
QFile
source
(
sourceDevice
);
while
(
bloc
ksCopied
<
bloc
ksToCopy
)
{
if
(
!
(
rval
=
readData
(
source
,
buffer
,
readOffset
+
bloc
kSize
*
bloc
ksCopied
*
copyDirection
,
bloc
kSize
)))
while
(
chun
ksCopied
<
chun
ksToCopy
)
{
if
(
!
(
rval
=
readData
(
source
,
buffer
,
readOffset
+
chun
kSize
*
chun
ksCopied
*
copyDirection
,
chun
kSize
)))
break
;
if
(
!
(
rval
=
writeData
(
target
,
buffer
,
writeOffset
+
bloc
kSize
*
bloc
ksCopied
*
copyDirection
)))
if
(
!
(
rval
=
writeData
(
target
,
buffer
,
writeOffset
+
chun
kSize
*
chun
ksCopied
*
copyDirection
)))
break
;
bytesWritten
+=
buffer
.
size
();
if
(
++
bloc
ksCopied
*
100
/
bloc
ksToCopy
!=
percent
)
{
percent
=
bloc
ksCopied
*
100
/
bloc
ksToCopy
;
if
(
++
chun
ksCopied
*
100
/
chun
ksToCopy
!=
percent
)
{
percent
=
chun
ksCopied
*
100
/
chun
ksToCopy
;
if
(
percent
%
5
==
0
&&
timer
.
elapsed
()
>
1000
)
{
const
qint64
mibsPerSec
=
(
bloc
ksCopied
*
bloc
kSize
/
1024
/
1024
)
/
(
timer
.
elapsed
()
/
1000
);
const
qint64
mibsPerSec
=
(
chun
ksCopied
*
chun
kSize
/
1024
/
1024
)
/
(
timer
.
elapsed
()
/
1000
);
const
qint64
estSecsLeft
=
(
100
-
percent
)
*
timer
.
elapsed
()
/
percent
/
1000
;
reportText
=
xi18nc
(
"@info:progress"
,
"Copying %1 MiB/second, estimated time left: %2"
,
mibsPerSec
,
QTime
(
0
,
0
).
addSecs
(
estSecsLeft
).
toString
());
Q_EMIT
report
(
reportText
);
...
...
@@ -262,11 +262,11 @@ QVariantMap ExternalCommandHelper::CopyFileData(const QString& sourceDevice, con
// copy the remainder
if
(
rval
&&
lastBlock
>
0
)
{
Q_ASSERT
(
lastBlock
<
bloc
kSize
);
Q_ASSERT
(
lastBlock
<
chun
kSize
);
const
qint64
lastBlockReadOffset
=
copyDirection
==
CopyDirection
::
Left
?
readOffset
+
bloc
kSize
*
bloc
ksCopied
:
sourceOffset
;
const
qint64
lastBlockWriteOffset
=
copyDirection
==
CopyDirection
::
Left
?
writeOffset
+
bloc
kSize
*
bloc
ksCopied
:
targetOffset
;
reportText
=
xi18nc
(
"@info:progress"
,
"Copying remainder of
bloc
k size %1 from %2 to %3."
,
lastBlock
,
lastBlockReadOffset
,
lastBlockWriteOffset
);
const
qint64
lastBlockReadOffset
=
copyDirection
==
CopyDirection
::
Left
?
readOffset
+
chun
kSize
*
chun
ksCopied
:
sourceOffset
;
const
qint64
lastBlockWriteOffset
=
copyDirection
==
CopyDirection
::
Left
?
writeOffset
+
chun
kSize
*
chun
ksCopied
:
targetOffset
;
reportText
=
xi18nc
(
"@info:progress"
,
"Copying remainder of
chun
k size %1 from %2 to %3."
,
lastBlock
,
lastBlockReadOffset
,
lastBlockWriteOffset
);
Q_EMIT
report
(
reportText
);
rval
=
readData
(
source
,
buffer
,
lastBlockReadOffset
,
lastBlock
);
...
...
@@ -280,7 +280,7 @@ QVariantMap ExternalCommandHelper::CopyFileData(const QString& sourceDevice, con
}
}
reportText
=
xi18ncp
(
"@info:progress argument 2 is a string such as 7 bytes (localized accordingly)"
,
"Copying 1
bloc
k (%2) finished."
,
"Copying %1
bloc
ks (%2) finished."
,
bloc
ksCopied
,
i18np
(
"1 byte"
,
"%1 bytes"
,
bytesWritten
));
reportText
=
xi18ncp
(
"@info:progress argument 2 is a string such as 7 bytes (localized accordingly)"
,
"Copying 1
chun
k (%2) finished."
,
"Copying %1
chun
ks (%2) finished."
,
chun
ksCopied
,
i18np
(
"1 byte"
,
"%1 bytes"
,
bytesWritten
));
Q_EMIT
report
(
reportText
);
reply
[
QStringLiteral
(
"success"
)]
=
rval
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment