Skip to content

Commit

Permalink
fix: Copying a large number of empty files and folders on the USB dri…
Browse files Browse the repository at this point in the history
…ve, with incorrect progress bar statistics

The reason for the inaccurate data statistics here is that we calculated the size of the directory as 4096, but in the write statistics of the USB drive, we calculated the size by reading and writing how many block blocks were written. The size of the directory and the 0kb file were calculated as a numerical value in the USB drive, which caused our own calculated values to not match. When modifying the statistics size, we are copying thread blocking statistics and then using our own statistics method.

Log: Copying a large number of empty files and folders on the USB drive, with incorrect progress bar statistics
Bug: https://pms.uniontech.com/bug-view-236707.html
  • Loading branch information
liyigang1 committed Dec 27, 2023
1 parent a597233 commit 2627b69
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 1 addition & 7 deletions src/dfm-base/utils/filestatisticsjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ void FileStatisticsJob::setSizeInfo()
{
d->sizeInfo->fileCount = static_cast<quint32>(d->filesCount);
d->sizeInfo->totalSize = d->totalProgressSize;
d->sizeInfo->dirSize = d->sizeInfo->dirSize == 0 ? FileUtils::getMemoryPageSize() : d->sizeInfo->dirSize;
d->sizeInfo->dirSize = FileUtils::getMemoryPageSize();
}

void FileStatisticsJob::statistcsOtherFileSystem()
Expand Down Expand Up @@ -466,12 +466,6 @@ void FileStatisticsJob::statistcsOtherFileSystem()
}

if (info->isAttributes(OptInfoType::kIsDir)) {
if (d->sizeInfo->dirSize == 0) {
struct stat statInfo;

if (0 == stat(info->urlOf(UrlInfoType::kUrl).path().toStdString().data(), &statInfo))
d->sizeInfo->dirSize = statInfo.st_size == 0 ? FileUtils::getMemoryPageSize() : static_cast<quint16>(statInfo.st_size);
}
directory_queue << url;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void AbstractWorker::setWorkArgs(const JobHandlePointer handle, const QList<QUrl
}
connect(this, &AbstractWorker::startWork, this, &AbstractWorker::doWork);
workData.reset(new WorkerData);
workData->dirSize = FileUtils::getMemoryPageSize();
this->handle = handle;
initHandleConnects(handle);
this->sourceUrls = sources;
Expand Down Expand Up @@ -194,17 +195,21 @@ bool AbstractWorker::statisticsFilesSize()

if (isSourceFileLocal) {
const SizeInfoPointer &fileSizeInfo = FileOperationsUtils::statisticsFilesSize(sourceUrls, true);

allFilesList = fileSizeInfo->allFiles;
sourceFilesTotalSize = fileSizeInfo->totalSize;
workData->dirSize = fileSizeInfo->dirSize;
sourceFilesCount = fileSizeInfo->fileCount;
} else {
statisticsFilesSizeJob.reset(new DFMBASE_NAMESPACE::FileStatisticsJob());
connect(statisticsFilesSizeJob.data(), &DFMBASE_NAMESPACE::FileStatisticsJob::finished,
this, &AbstractWorker::onStatisticsFilesSizeFinish, Qt::DirectConnection);
connect(statisticsFilesSizeJob.data(), &DFMBASE_NAMESPACE::FileStatisticsJob::sizeChanged, this, &AbstractWorker::onStatisticsFilesSizeUpdate, Qt::DirectConnection);
statisticsFilesSizeJob->start(sourceUrls);
while(!statisticsFilesSizeJob->isFinished()) {
QThread::msleep(10);
}
const SizeInfoPointer &fileSizeInfo = statisticsFilesSizeJob->getFileSizeInfo();
allFilesList = fileSizeInfo->allFiles;
sourceFilesTotalSize = fileSizeInfo->totalSize;
workData->dirSize = fileSizeInfo->dirSize;
sourceFilesCount = fileSizeInfo->fileCount;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ bool FileOperateBaseWorker::doCopyFile(const FileInfoPointer &fromInfo, const Fi
} else if (fromInfo->isAttributes(OptInfoType::kIsDir)) {
result = checkAndCopyDir(fromInfo, newTargetInfo, skip);
if (result || skip)
workData->zeroOrlinkOrDirWriteSize += workData->dirSize;
workData->zeroOrlinkOrDirWriteSize += workData->dirSize <= 0 ? FileUtils::getMemoryPageSize() : workData->dirSize;
} else {
result = checkAndCopyFile(fromInfo, newTargetInfo, skip);
}
Expand Down Expand Up @@ -1324,7 +1324,8 @@ void FileOperateBaseWorker::determineCountProcessType()

if (targetIsRemovable) {
workData->exBlockSyncEveryWrite = FileOperationsUtils::blockSync();
countWriteType = workData->exBlockSyncEveryWrite ? CountWriteSizeType::kCustomizeType : CountWriteSizeType::kWriteBlockType;
countWriteType = workData->exBlockSyncEveryWrite ? CountWriteSizeType::kCustomizeType
: CountWriteSizeType::kCustomizeType;

Check warning on line 1328 in src/plugins/common/core/dfmplugin-fileoperations/fileoperations/fileoperationutils/fileoperatebaseworker.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Finding the same expression in both branches of ternary operator is suspicious as the same code is executed regardless of the condition.
targetDeviceStartSectorsWritten = workData->exBlockSyncEveryWrite ? 0 : getSectorsWritten();

workData->isBlockDevice = true;
Expand Down

0 comments on commit 2627b69

Please sign in to comment.