Skip to content

Commit eb2e783

Browse files
committed
Add 'percent complete' log output to --copyfile utility.
1 parent da49555 commit eb2e783

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

mythtv/programs/mythutil/fileutils.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,36 @@ static int CopyFile(const MythUtilCommandLineParser &cmdline)
6767
return GENERIC_EXIT_NOT_OK;
6868
}
6969

70+
long long totalBytes = srcRB->GetRealFileSize();
71+
long long totalBytesCopied = 0;
72+
int percentComplete = 0;
7073
bool ok = true;
7174
int r;
7275
int ret;
73-
int written = 0;
7476
while (ok && ((r = srcRB->Read(buf, readSize)) > 0))
7577
{
7678
ret = destRB->Write(buf, r);
7779
if (ret < 0)
7880
{
7981
LOG(VB_GENERAL, LOG_ERR,
80-
QString("ERROR, couldn't write at offset %1").arg(written));
82+
QString("ERROR, couldn't write at offset %1")
83+
.arg(totalBytesCopied));
8184
ok = false;
8285
}
8386
else
84-
written += ret;
87+
totalBytesCopied += ret;
88+
89+
percentComplete = totalBytesCopied * 100 / totalBytes;
90+
if ((percentComplete % 5) == 0)
91+
LOG(VB_GENERAL, LOG_INFO,
92+
QString("%1 bytes copied, %2%% complete")
93+
.arg(totalBytesCopied).arg(percentComplete));
8594
}
8695

8796
LOG(VB_GENERAL, LOG_INFO,
88-
QString("Wrote %1 bytes total").arg(written));
97+
QString("Wrote %1 bytes total").arg(totalBytesCopied));
98+
99+
LOG(VB_GENERAL, LOG_INFO, "Waiting for write buffer to flush");
89100

90101
delete buf;
91102
delete srcRB;

0 commit comments

Comments
 (0)