diff --git a/src/libdbm/installer/qtbaseinstaller.cpp b/src/libdbm/installer/qtbaseinstaller.cpp index ed874395..56e01543 100644 --- a/src/libdbm/installer/qtbaseinstaller.cpp +++ b/src/libdbm/installer/qtbaseinstaller.cpp @@ -483,6 +483,7 @@ void QtBaseInstaller::modifyBootGrubFile(QString grub_file_name) if (!writeFile.open(QIODevice::ReadWrite|QIODevice::Truncate)) { qCritical() << writeFile.errorString(); + readFile.close(); return; } diff --git a/src/libdbm/util/sevenzip.cpp b/src/libdbm/util/sevenzip.cpp index 7f190bd6..31d9e9ec 100644 --- a/src/libdbm/util/sevenzip.cpp +++ b/src/libdbm/util/sevenzip.cpp @@ -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(); diff --git a/src/libdbm/util/utils.cpp b/src/libdbm/util/utils.cpp index ee3d306b..53818877 100644 --- a/src/libdbm/util/utils.cpp +++ b/src/libdbm/util/utils.cpp @@ -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; } @@ -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(); @@ -495,7 +506,10 @@ QList 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"); diff --git a/src/vendor/src/libxsys/DiskUtil/DiskUtil.cpp b/src/vendor/src/libxsys/DiskUtil/DiskUtil.cpp index 94b319b7..99f3724b 100644 --- a/src/vendor/src/libxsys/DiskUtil/DiskUtil.cpp +++ b/src/vendor/src/libxsys/DiskUtil/DiskUtil.cpp @@ -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(); diff --git a/src/vendor/src/libxsys/FileSystem/FileSystem.cpp b/src/vendor/src/libxsys/FileSystem/FileSystem.cpp index c3d4b28d..e1989d82 100644 --- a/src/vendor/src/libxsys/FileSystem/FileSystem.cpp +++ b/src/vendor/src/libxsys/FileSystem/FileSystem.cpp @@ -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(); @@ -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(); @@ -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(); @@ -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()) {