forked from qt-creator/qt-creator
		
	add/unify i/o error handling
lots of use of Utils::FileSaver and Utils::FileReader Task-number: QTCREATORBUG-1619
This commit is contained in:
		| @@ -55,6 +55,7 @@ | ||||
| #include <utils/qtcprocess.h> | ||||
| #include <utils/synchronousprocess.h> | ||||
| #include <utils/environment.h> | ||||
| #include <utils/fileutils.h> | ||||
| #include <vcsbase/vcsbaseeditor.h> | ||||
| #include <vcsbase/vcsbaseoutputwindow.h> | ||||
| #include <vcsbase/vcsbaseplugin.h> | ||||
| @@ -1784,9 +1785,10 @@ bool GitClient::getCommitData(const QString &workingDirectory, | ||||
|     // Read description | ||||
|     const QString descriptionFile = gitDir.absoluteFilePath(QLatin1String("description")); | ||||
|     if (QFileInfo(descriptionFile).isFile()) { | ||||
|         QFile file(descriptionFile); | ||||
|         if (file.open(QIODevice::ReadOnly|QIODevice::Text)) | ||||
|             commitData->panelInfo.description = commandOutputFromLocal8Bit(file.readAll()).trimmed(); | ||||
|         Utils::FileReader reader; | ||||
|         if (!reader.fetch(descriptionFile, QIODevice::Text, errorMessage)) | ||||
|             return false; | ||||
|         commitData->panelInfo.description = commandOutputFromLocal8Bit(reader.data()).trimmed(); | ||||
|     } | ||||
|  | ||||
|     // Run status. Note that it has exitcode 1 if there are no added files. | ||||
| @@ -1868,14 +1870,10 @@ bool GitClient::getCommitData(const QString &workingDirectory, | ||||
|             const QFileInfo templateFileInfo(templateFilename); | ||||
|             if (templateFileInfo.isRelative()) | ||||
|                 templateFilename = repoDirectory + QLatin1Char('/') + templateFilename; | ||||
|             QFile templateFile(templateFilename); | ||||
|             if (templateFile.open(QIODevice::ReadOnly|QIODevice::Text)) { | ||||
|                 *commitTemplate = QString::fromLocal8Bit(templateFile.readAll()); | ||||
|             } else { | ||||
|                 qWarning("Unable to read commit template %s: %s", | ||||
|                          qPrintable(templateFilename), | ||||
|                          qPrintable(templateFile.errorString())); | ||||
|             } | ||||
|             Utils::FileReader reader; | ||||
|             if (!reader.fetch(templateFilename, QIODevice::Text, errorMessage)) | ||||
|                 return false; | ||||
|             *commitTemplate = QString::fromLocal8Bit(reader.data()); | ||||
|         } | ||||
|     } | ||||
|     return true; | ||||
|   | ||||
| @@ -58,6 +58,7 @@ | ||||
|  | ||||
| #include <utils/qtcassert.h> | ||||
| #include <utils/parameteraction.h> | ||||
| #include <utils/fileutils.h> | ||||
|  | ||||
| #include <vcsbase/basevcseditorfactory.h> | ||||
| #include <vcsbase/vcsbaseeditor.h> | ||||
| @@ -693,18 +694,15 @@ void GitPlugin::startCommit(bool amend) | ||||
|         qDebug() << Q_FUNC_INFO << data << commitTemplate; | ||||
|  | ||||
|     // Start new temp file with message template | ||||
|     QTemporaryFile changeTmpFile; | ||||
|     changeTmpFile.setAutoRemove(false); | ||||
|     if (!changeTmpFile.open()) { | ||||
|         VCSBase::VCSBaseOutputWindow::instance()->append(tr("Cannot create temporary file: %1").arg(changeTmpFile.errorString())); | ||||
|     Utils::TempFileSaver saver; | ||||
|     // Keep the file alive, else it removes self and forgets its name | ||||
|     saver.setAutoRemove(false); | ||||
|     saver.write(commitTemplate.toLocal8Bit()); | ||||
|     if (!saver.finalize()) { | ||||
|         VCSBase::VCSBaseOutputWindow::instance()->append(saver.errorString()); | ||||
|         return; | ||||
|     } | ||||
|     m_commitMessageFileName = changeTmpFile.fileName(); | ||||
|     changeTmpFile.write(commitTemplate.toLocal8Bit()); | ||||
|     changeTmpFile.flush(); | ||||
|     // Keep the file alive, else it removes self and forgets | ||||
|     // its name | ||||
|     changeTmpFile.close(); | ||||
|     m_commitMessageFileName = saver.fileName(); | ||||
|     openSubmitEditor(m_commitMessageFileName, data, amend); | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user