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:
@@ -40,6 +40,7 @@
|
||||
#include "maemodeviceconfigurations.h"
|
||||
#include "maemokeydeployer.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/ssh/sshkeygenerator.h>
|
||||
|
||||
#include <QtCore/QDir>
|
||||
@@ -421,13 +422,10 @@ private:
|
||||
|
||||
bool saveFile(const QString &filePath, const QByteArray &data)
|
||||
{
|
||||
QFile file(filePath);
|
||||
const bool canOpen = file.open(QIODevice::WriteOnly);
|
||||
if (canOpen)
|
||||
file.write(data);
|
||||
if (!canOpen || file.error() != QFile::NoError) {
|
||||
QMessageBox::critical(this, tr("Could Not Save File"),
|
||||
tr("Failed to save key file %1: %2").arg(filePath, file.errorString()));
|
||||
Utils::FileSaver saver(filePath);
|
||||
saver.write(data);
|
||||
if (!saver.finalize()) {
|
||||
QMessageBox::critical(this, tr("Could Not Save Key File"), saver.errorString());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "maemokeydeployer.h"
|
||||
|
||||
#include <utils/ssh/sshremoteprocessrunner.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QtCore/QFile>
|
||||
|
||||
@@ -56,13 +57,9 @@ void MaemoKeyDeployer::deployPublicKey(const SshConnectionParameters &sshParams,
|
||||
cleanup();
|
||||
m_deployProcess = SshRemoteProcessRunner::create(sshParams);
|
||||
|
||||
QFile keyFile(keyFilePath);
|
||||
QByteArray key;
|
||||
const bool keyFileAccessible = keyFile.open(QIODevice::ReadOnly);
|
||||
if (keyFileAccessible)
|
||||
key = keyFile.readAll();
|
||||
if (!keyFileAccessible || keyFile.error() != QFile::NoError) {
|
||||
emit error(tr("Could not read public key file '%1'.").arg(keyFilePath));
|
||||
Utils::FileReader reader;
|
||||
if (!reader.fetch(keyFilePath)) {
|
||||
emit error(tr("Public key error: %1").arg(reader.errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -72,7 +69,7 @@ void MaemoKeyDeployer::deployPublicKey(const SshConnectionParameters &sshParams,
|
||||
SLOT(handleKeyUploadFinished(int)));
|
||||
const QByteArray command = "test -d .ssh "
|
||||
"|| mkdir .ssh && chmod 0700 .ssh && echo '"
|
||||
+ key + "' >> .ssh/authorized_keys && chmod 0600 .ssh/authorized_keys";
|
||||
+ reader.data() + "' >> .ssh/authorized_keys && chmod 0600 .ssh/authorized_keys";
|
||||
m_deployProcess->run(command);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "maemodeviceconfigurations.h"
|
||||
|
||||
#include <utils/ssh/sshkeygenerator.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtGui/QApplication>
|
||||
@@ -124,17 +125,10 @@ void MaemoSshConfigDialog::saveKey(bool publicKey)
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
|
||||
QFile file(fileName);
|
||||
const bool canOpen = file.open(QIODevice::WriteOnly);
|
||||
if (canOpen)
|
||||
file.write(publicKey
|
||||
Utils::FileSaver saver(fileName);
|
||||
saver.write(publicKey
|
||||
? m_keyGenerator->publicKey()
|
||||
: m_keyGenerator->privateKey());
|
||||
if (!canOpen || file.error() != QFile::NoError) {
|
||||
QMessageBox::critical(this, tr("Error writing file"),
|
||||
tr("Could not write file '%1':\n %2")
|
||||
.arg(fileName, file.errorString()));
|
||||
} else if (!publicKey) {
|
||||
if (saver.finalize(this) && !publicKey)
|
||||
emit privateKeyGenerated(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
#include <qt4projectmanager/qt4project.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <utils/filesystemwatcher.h>
|
||||
|
||||
@@ -965,10 +966,6 @@ AbstractQt4MaemoTarget::ActionStatus AbstractRpmBasedQt4MaemoTarget::createSpeci
|
||||
{
|
||||
if (QFileInfo(specFilePath()).exists())
|
||||
return NoActionRequired;
|
||||
QSharedPointer<QFile> specFile
|
||||
= openFile(specFilePath(), QIODevice::WriteOnly, 0);
|
||||
if (!specFile)
|
||||
return ActionFailed;
|
||||
QByteArray initialContent(
|
||||
"Name: %%name%%\n"
|
||||
"Summary: <insert short description here>\n"
|
||||
@@ -1010,8 +1007,9 @@ AbstractQt4MaemoTarget::ActionStatus AbstractRpmBasedQt4MaemoTarget::createSpeci
|
||||
"# Add post-uninstall scripts here."
|
||||
);
|
||||
initialContent.replace("%%name%%", project()->displayName().toUtf8());
|
||||
return specFile->write(initialContent) == initialContent.count()
|
||||
? ActionSuccessful : ActionFailed;
|
||||
Utils::FileSaver saver(specFilePath());
|
||||
saver.write(initialContent);
|
||||
return saver.finalize() ? ActionSuccessful : ActionFailed;
|
||||
}
|
||||
|
||||
void AbstractRpmBasedQt4MaemoTarget::handleTargetAddedSpecial()
|
||||
|
||||
Reference in New Issue
Block a user