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: Optimize QFile operation #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/libdbm/installer/qtbaseinstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ void QtBaseInstaller::modifyBootGrubFile(QString grub_file_name)

if (!writeFile.open(QIODevice::ReadWrite|QIODevice::Truncate)) {
qCritical() << writeFile.errorString();
readFile.close();
return;
}

Expand Down
7 changes: 6 additions & 1 deletion src/libdbm/util/sevenzip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ void SevenZipProcessParser::run()
qDebug() << "Start Parse";
QFile progress(m_progressFilename);
// qDebug() << "progressFilename:" << m_progressFilename;
progress.open(QIODevice::ReadOnly);

if (!progress.open(QIODevice::ReadOnly)) {
qDebug() << "error open file: " << progress.fileName();
return;
}

while (QProcess::NotRunning != m_sevenZip->state()) {
QByteArray readed = progress.readLine();
QString progressStr = QString::fromUtf8(readed).split("\b").last();
Expand Down
20 changes: 17 additions & 3 deletions src/libdbm/util/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,19 @@ bool CheckInstallDisk(const QString &targetDev)
}

QFile UOS(":src/UOS");
UOS.open(QIODevice::ReadOnly);
if (!UOS.open(QIODevice::ReadOnly)) {
qDebug() << "error open file: " << UOS.fileName();
test.close();
return false;
}

QByteArray data = UOS.readAll();

if (data.length() != test.write(data)) {
qDebug() << "erro write file: " << UOS.fileName();
test.close();
UOS.close();
test.remove();
return false;
}

Expand All @@ -411,7 +419,10 @@ bool isUsbDisk(const QString &dev)
QString out = XSys::FS::TmpFilePath("diskutil_isusb_out");
XSys::SynExec("bash", QString("-c \" diskutil info %1 > \"%2\" \" ").arg(dev).arg(out));
QFile outfile(out);
outfile.open(QIODevice::ReadOnly);
if (!outfile.open(QIODevice::ReadOnly)) {
qDebug() << "error open file: " << outfile.fileName();
return false;
}
QString info = outfile.readAll();
outfile.close();
outfile.remove();
Expand Down Expand Up @@ -495,7 +506,10 @@ QList<DeviceInfo> ListUsbDrives()
QString out = XSys::FS::TmpFilePath("diskutil_out");
XSys::SynExec("bash", QString("-c \" diskutil list > \"%1\" \" ").arg(out));
QFile outfile(out);
outfile.open(QIODevice::ReadOnly);
if (!outfile.open(QIODevice::ReadOnly)) {
qDebug() << "error open file: " << outfile.fileName();
return deviceList;
}
QString diskutilList = outfile.readAll();
QStringList usbdevsL = diskutilList.split("\n").filter(QRegExp("(FAT|Microsoft)")).join(" ").split(" ").filter("disk");

Expand Down
11 changes: 9 additions & 2 deletions src/vendor/src/libxsys/DiskUtil/DiskUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,18 @@ XSys::Result InstallBootloader(const QString &targetDev)
qDebug() << "dump pbr begin";
QString tmpPbrPath = XSys::FS::TmpFilePath("ldlinux.bin");
QFile pbr(tmpPbrPath);
pbr.open(QIODevice::WriteOnly);
if (!pbr.open(QIODevice::WriteOnly)) {
qDebug() << "error open file: " << pbr.fileName();
return XSys::Result(XSys::Result::Failed, pbr.errorString());
}

QString targetPhyName = "\\\\.\\" + QString(targetDev).remove('\\');
QFile targetPhy(targetPhyName);
targetPhy.open(QIODevice::ReadOnly);
if (!targetPhy.open(QIODevice::ReadOnly)) {
qDebug() << "error open file: " << targetPhy.fileName();
pbr.close();
return XSys::Result(XSys::Result::Failed, targetPhy.errorString());
}

pbr.write(targetPhy.read(512));
targetPhy.close();
Expand Down
14 changes: 12 additions & 2 deletions src/vendor/src/libxsys/FileSystem/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ bool InsertFileData(const QString &filename, const QByteArray &data)
}
if (!file.write(data)) {
qWarning() << "Insert Tmp FileData Failed, Can not Write" << filename;
file.close();
return false;
}
file.close();
Expand All @@ -75,6 +76,7 @@ QString InsertTmpFile(const QString &fileurl, const QString &distFilename)
}
if (!InsertFileData(filename, file.readAll())) {
qWarning() << "Insert Tmp File Failed" << fileurl;
file.close();
return filename;
}
file.close();
Expand All @@ -88,6 +90,7 @@ bool InsertFile(const QString &fileurl, const QString &fullpath)
return false;
}
if (!InsertFileData(fullpath, file.readAll())) {
file.close();
return false;
}
file.close();
Expand Down Expand Up @@ -117,8 +120,15 @@ bool CpFile(const QString &srcName, const QString &desName)
bool ret = true;
QFile srcFile(srcName);
QFile desFile(desName);
srcFile.open(QIODevice::ReadOnly);
desFile.open(QIODevice::WriteOnly);
if (!srcFile.open(QIODevice::ReadOnly)) {
qWarning() << "error open file: " << srcName;
return false;
}
if (!desFile.open(QIODevice::WriteOnly)) {
qWarning() << "error open file: " << desName;
srcFile.close();
return false;
}
QByteArray data = srcFile.readAll();
qint64 writeBytes = desFile.write(data);
if (writeBytes != data.size()) {
Expand Down