Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Copying a large number of empty files and folders on the USB drive, with incorrect progress bar statistics #1674

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
} 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 @@

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