Skip to content

Commit

Permalink
fix: [io] After the small files copied, the task dialog does not disa…
Browse files Browse the repository at this point in the history
…ppear for a long time

Modify the synchronization policy so that for files copied to a USB flash drive, this file is synchronized once.

Log: After the small files copied, the task dialog does not disappear for a long time
Bug: https://pms.uniontech.com/bug-view-208033.html
  • Loading branch information
liyigang1 authored and deepin-bot[bot] committed Jul 28, 2023
1 parent 63bb903 commit 2fc4890
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@ void DoCopyFileWorker::createExBlockFileCopyInfo(const FileInfoPointer fromInfo,
QThread::msleep(10);
}

void DoCopyFileWorker::syncBlockFile(const FileInfoPointer toInfo)
{
if (!workData->isBlockDevice)
return;
std::string stdStr = toInfo->urlOf(UrlInfoType::kUrl).path().toUtf8().toStdString();
int tofd = open(stdStr.data(), O_RDONLY);
if (-1 != tofd) {
syncfs(tofd);
close(tofd);
}
}

// copy thread using
bool DoCopyFileWorker::doCopyFilePractically(const FileInfoPointer fromInfo, const FileInfoPointer toInfo, bool *skip)
{
Expand Down Expand Up @@ -360,6 +372,8 @@ bool DoCopyFileWorker::doCopyFilePractically(const FileInfoPointer fromInfo, con
delete[] data;
data = nullptr;

syncBlockFile(toInfo);

// 对文件加权
setTargetPermissions(fromInfo, toInfo);
if (!stateCheck())
Expand Down Expand Up @@ -751,6 +765,7 @@ bool DoCopyFileWorker::doWriteFile(const FileInfoPointer &fromInfo, const FileIn
toDevice->flush();
}
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class DoCopyFileWorker : public QObject
char *buffer = nullptr,
const bool isDir = false,
const QFileDevice::Permissions permission = QFileDevice::Permission::ReadOwner);
void syncBlockFile(const FileInfoPointer toInfo);

private:
QSharedPointer<QWaitCondition> waitCondition { nullptr };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ void FileOperateBaseWorker::determineCountProcessType()

if (targetIsRemovable) {
countWriteType = CountWriteSizeType::kWriteBlockType;
workData->isBlockDevice = true;
targetDeviceStartSectorsWritten = getSectorsWritten();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class WorkerData
QMap<AbstractJobHandler::JobErrorType, AbstractJobHandler::SupportAction> errorOfAction;
std::atomic_bool needSyncEveryRW { false };
std::atomic_bool isFsTypeVfat { false };
std::atomic_bool isBlockDevice { false };
std::atomic_int64_t currentWriteSize { 0 };
QAtomicInteger<qint64> zeroOrlinkOrDirWriteSize { 0 }; // The copy size is 0. The write statistics size of the linked file and directory
QAtomicInteger<qint64> blockRenameWriteSize { 0 }; // The copy size is 0. The write statistics size of the linked file and directory
Expand Down

0 comments on commit 2fc4890

Please sign in to comment.