#include <qt4project.h>
#include <qt4target.h>
#include <utils/environment.h>
+#include <utils/fileutils.h>
#include <QtCore/QDateTime>
#include <QtCore/QProcess>
= templatesDirPath + QLatin1Char('/') + fileName;
const QString destFile
= debianDirPath + QLatin1Char('/') + fileName;
- if (!QFile::copy(srcFile, destFile)) {
+ if (fileName == QLatin1String("rules")) {
+ if (!adaptRulesFile(srcFile, destFile))
+ return false;
+ } else if (!QFile::copy(srcFile, destFile)) {
raiseError(tr("Could not copy file '%1' to '%2'")
.arg(QDir::toNativeSeparators(srcFile),
QDir::toNativeSeparators(destFile)));
return false;
}
-
- if (fileName == QLatin1String("rules"))
- adaptRulesFile(destFile);
}
QFile magicFile(magicFilePath);
rulesContent = contentAsString.toLocal8Bit();
}
-void MaemoDebianPackageCreationStep::adaptRulesFile(const QString &rulesFilePath)
+bool MaemoDebianPackageCreationStep::adaptRulesFile(
+ const QString &templatePath, const QString &rulesFilePath)
{
- QFile rulesFile(rulesFilePath);
- rulesFile.setPermissions(rulesFile.permissions() | QFile::ExeUser);
- if (!rulesFile.open(QIODevice::ReadWrite)) {
- qWarning("Cannot open rules file for Maemo6 icon path adaptation.");
- return;
+ Utils::FileReader reader;
+ if (!reader.fetch(templatePath)) {
+ raiseError(reader.errorString());
+ return false;
}
- QByteArray content = rulesFile.readAll();
+ QByteArray content = reader.data();
const int makeInstallLine = content.indexOf("\t$(MAKE) INSTALL_ROOT");
if (makeInstallLine == -1)
- return;
+ return true;
const int makeInstallEol = content.indexOf('\n', makeInstallLine);
if (makeInstallEol == -1)
- return;
- QString desktopFileDir = QFileInfo(rulesFile).dir().path()
+ return true;
+ QString desktopFileDir = QFileInfo(rulesFilePath).path()
+ QLatin1Char('/') + maemoTarget()->packageName()
+ QLatin1String("/usr/share/applications/");
const Qt4BuildConfiguration * const bc = qt4BuildConfiguration();
if (!(bc->qmakeBuildConfiguration() & QtVersion::DebugBuild))
ensureShlibdeps(content);
- rulesFile.resize(0);
- rulesFile.write(content);
+ Utils::FileSaver saver(rulesFilePath);
+ saver.write(content);
+ if (!saver.finalize()) {
+ raiseError(saver.errorString());
+ return false;
+ }
+ QFile rulesFile(rulesFilePath);
+ rulesFile.setPermissions(rulesFile.permissions() | QFile::ExeUser);
+ return true;
}
void MaemoDebianPackageCreationStep::addWorkaroundForHarmattanBug(QByteArray &rulesFileContent,
#include <projectexplorer/target.h>
#include <qt4projectmanager/qmakestep.h>
#include <qt4projectmanager/qt4buildconfiguration.h>
+#include <utils/fileutils.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
return false;
}
} else {
- if (!QFile::copy(srcFilePath, tgtFilePath)) {
- emit progressReport(tr("Could not copy file '%1' to '%2'.")
- .arg(QDir::toNativeSeparators(srcFilePath),
- QDir::toNativeSeparators(tgtFilePath)));
- return false;
- }
- QCoreApplication::processEvents();
-
if (tgtFilePath == m_tmpProjectDir + QLatin1String("/debian/rules")) {
- QFile rulesFile(tgtFilePath);
- if (!rulesFile.open(QIODevice::ReadWrite)) {
- emit progressReport(tr("Error: Cannot open file '%1'.")
- .arg(QDir::toNativeSeparators(tgtFilePath)));
+ Utils::FileReader reader;
+ if (!reader.fetch(srcFilePath)) {
+ emit progressReport(reader.errorString(), ErrorOutput);
return false;
}
- QByteArray rulesContents = rulesFile.readAll();
+ QByteArray rulesContents = reader.data();
rulesContents.replace("$(MAKE) clean", "# $(MAKE) clean");
rulesContents.replace("# Add here commands to configure the package.",
"qmake " + QFileInfo(m_project->file()->fileName()).fileName().toLocal8Bit());
MaemoDebianPackageCreationStep::ensureShlibdeps(rulesContents);
- rulesFile.resize(0);
- rulesFile.write(rulesContents);
+ Utils::FileSaver saver(tgtFilePath);
+ saver.write(rulesContents);
+ if (!saver.finalize()) {
+ emit progressReport(saver.errorString(), ErrorOutput);
+ return false;
+ }
+ } else {
+ QFile srcFile(srcFilePath);
+ if (!srcFile.copy(tgtFilePath)) {
+ emit progressReport(tr("Could not copy file '%1' to '%2': %3.")
+ .arg(QDir::toNativeSeparators(srcFilePath),
+ QDir::toNativeSeparators(tgtFilePath),
+ srcFile.errorString()));
+ return false;
+ }
}
}
return true;
QDir debianDir(m_tmpProjectDir + QLatin1String("/debian"));
const QStringList &fileNames = debianDir.entryList(QDir::Files);
foreach (const QString &fileName, fileNames) {
- QFile file(debianDir.filePath(fileName));
- if (!file.open(QIODevice::ReadWrite))
+ QString filePath = debianDir.filePath(fileName);
+ Utils::FileReader reader;
+ if (!reader.fetch(filePath))
return false;
- QByteArray contents = file.readAll();
+ QByteArray contents = reader.data();
const QByteArray crlf("\r\n");
if (!contents.contains(crlf))
continue;
contents.replace(crlf, "\n");
- file.resize(0);
- file.write(contents);
+ Utils::FileSaver saver(filePath);
+ saver.write(contents);
+ if (!saver.finalize())
+ return false;
}
return true;
}
if (desktopFilePath.isEmpty())
continue;
desktopFilePath.replace(model->projectDir(), m_tmpProjectDir);
- QFile desktopFile(desktopFilePath);
const QString executableFilePath = model->remoteExecutableFilePath();
if (executableFilePath.isEmpty()) {
qDebug("%s: Skipping subproject %s with missing deployment information.",
Q_FUNC_INFO, qPrintable(model->proFilePath()));
continue;
}
- if (!desktopFile.exists() || !desktopFile.open(QIODevice::ReadWrite)) {
+ Utils::FileReader reader;
+ if (!reader.fetch(desktopFilePath, error)) {
success = false;
- if (error) {
- *error = tr("Failed to adapt desktop file '%1'.")
- .arg(desktopFilePath);
- }
continue;
}
- QByteArray desktopFileContents = desktopFile.readAll();
+ QByteArray desktopFileContents = reader.data();
bool fileNeedsUpdate = addOrReplaceDesktopFileValue(desktopFileContents,
"Exec", executableFilePath.toUtf8());
if (fileNeedsUpdate) {
- desktopFile.resize(0);
- desktopFile.write(desktopFileContents);
+ Utils::FileSaver saver(desktopFilePath);
+ saver.write(desktopFileContents);
+ if (!saver.finalize(error))
+ success = false;
}
}
return success;
#include <utils/fileutils.h>
#include <utils/filesystemwatcher.h>
+#include <utils/fileutils.h>
#include <QtGui/QApplication>
#include <QtGui/QMainWindow>
QString *error)
{
const QString filePath = changeLogFilePath();
- MaemoGlobal::FileUpdate update(filePath);
- QSharedPointer<QFile> changeLog
- = openFile(filePath, QIODevice::ReadWrite, error);
- if (!changeLog)
+ Utils::FileReader reader;
+ if (!reader.fetch(filePath, error))
return false;
-
- QString content = QString::fromUtf8(changeLog->readAll());
+ QString content = QString::fromUtf8(reader.data());
content.replace(QRegExp(QLatin1String("\\([a-zA-Z0-9_\\.]+\\)")),
QLatin1Char('(') + version + QLatin1Char(')'));
- changeLog->resize(0);
- changeLog->write(content.toUtf8());
- changeLog->close();
- if (changeLog->error() != QFile::NoError) {
- if (error) {
- *error = tr("Error writing Debian changelog file '%1': %2")
- .arg(QDir::toNativeSeparators(changeLog->fileName()),
- changeLog->errorString());
- }
- return false;
- }
- return true;
+ MaemoGlobal::FileUpdate update(filePath);
+ Utils::FileSaver saver(filePath);
+ saver.write(content.toUtf8());
+ return saver.finalize(error);
}
QIcon AbstractDebBasedQt4MaemoTarget::packageManagerIcon(QString *error) const
QString *error)
{
const QString filePath = controlFilePath();
- MaemoGlobal::FileUpdate update(filePath);
- const QSharedPointer<QFile> controlFile
- = openFile(filePath, QIODevice::ReadWrite, error);
- if (!controlFile)
+ Utils::FileReader reader;
+ if (!reader.fetch(filePath, error))
return false;
const QPixmap pixmap(iconFilePath);
if (pixmap.isNull()) {
}
buffer.close();
iconAsBase64 = iconAsBase64.toBase64();
- QByteArray contents = controlFile->readAll();
+ QByteArray contents = reader.data();
const QByteArray iconFieldNameWithColon = IconFieldName + ':';
const int iconFieldPos = contents.startsWith(iconFieldNameWithColon)
? 0 : contents.indexOf('\n' + iconFieldNameWithColon);
contents.replace(oldIconStartPos, nextEolPos - oldIconStartPos,
' ' + iconAsBase64);
}
- controlFile->resize(0);
- controlFile->write(contents);
- if (controlFile->error() != QFile::NoError) {
- if (error) {
- *error = tr("Error writing file '%1': %2")
- .arg(QDir::toNativeSeparators(controlFile->fileName()),
- controlFile->errorString());
- }
- return false;
- }
- return true;
+ MaemoGlobal::FileUpdate update(filePath);
+ Utils::FileSaver saver(filePath);
+ saver.write(contents);
+ return saver.finalize(error);
}
QString AbstractDebBasedQt4MaemoTarget::packageName() const
if (!setControlFieldValue("Source", packageName.toUtf8()))
return false;
- QSharedPointer<QFile> changelogFile
- = openFile(changeLogFilePath(), QIODevice::ReadWrite, 0);
- if (!changelogFile)
+ Utils::FileReader reader;
+ if (!reader.fetch(changeLogFilePath()))
return false;
- QString changelogContents = QString::fromUtf8(changelogFile->readAll());
+ QString changelogContents = QString::fromUtf8(reader.data());
QRegExp pattern(QLatin1String("[^\\s]+( \\(\\d\\.\\d\\.\\d\\))"));
changelogContents.replace(pattern, packageName + QLatin1String("\\1"));
- if (!changelogFile->resize(0))
+ Utils::FileSaver saver(changeLogFilePath());
+ saver.write(changelogContents.toUtf8());
+ if (!saver.finalize())
return false;
- changelogFile->write(changelogContents.toUtf8());
- QSharedPointer<QFile> rulesFile
- = openFile(rulesFilePath(), QIODevice::ReadWrite, 0);
- if (!rulesFile)
+ if (!reader.fetch(rulesFilePath()))
return false;
- QByteArray rulesContents = rulesFile->readAll();
+ QByteArray rulesContents = reader.data();
const QString oldString = QLatin1String("debian/") + oldPackageName;
const QString newString = QLatin1String("debian/") + packageName;
rulesContents.replace(oldString.toUtf8(), newString.toUtf8());
- rulesFile->resize(0);
- rulesFile->write(rulesContents);
- if (rulesFile->error() != QFile::NoError
- || changelogFile->error() != QFile::NoError) {
- return false;
- }
- return true;
+ Utils::FileSaver rulesSaver(changeLogFilePath());
+ rulesSaver.write(rulesContents);
+ return rulesSaver.finalize();
}
QString AbstractDebBasedQt4MaemoTarget::packageManagerName() const
bool multiLine) const
{
QByteArray value;
- QFile controlFile(controlFilePath());
- if (!controlFile.open(QIODevice::ReadOnly))
+ Utils::FileReader reader;
+ if (!reader.fetch(controlFilePath()))
return value;
- const QByteArray &contents = controlFile.readAll();
+ const QByteArray &contents = reader.data();
const int keyPos = contents.indexOf(key.toUtf8() + ':');
if (keyPos == -1)
return value;
bool AbstractDebBasedQt4MaemoTarget::setControlFieldValue(const QByteArray &fieldName,
const QByteArray &fieldValue)
{
- QFile controlFile(controlFilePath());
- MaemoGlobal::FileUpdate update(controlFile.fileName());
- if (!controlFile.open(QIODevice::ReadWrite))
+ Utils::FileReader reader;
+ if (!reader.fetch(controlFilePath()))
return false;
- QByteArray contents = controlFile.readAll();
+ QByteArray contents = reader.data();
if (adaptControlFileField(contents, fieldName, fieldValue)) {
- controlFile.resize(0);
- controlFile.write(contents);
+ MaemoGlobal::FileUpdate update(controlFilePath());
+ Utils::FileSaver saver(changeLogFilePath());
+ saver.write(contents);
+ return saver.finalize();
}
return true;
}
bool AbstractDebBasedQt4MaemoTarget::adaptRulesFile()
{
- QFile rulesFile(rulesFilePath());
- if (!rulesFile.open(QIODevice::ReadWrite)) {
- raiseError(tr("Packaging Error: Cannot open file '%1'.")
- .arg(QDir::toNativeSeparators(rulesFilePath())));
+ Utils::FileReader reader;
+ if (!reader.fetch(rulesFilePath())) {
+ raiseError(reader.errorString());
return false;
}
- QByteArray rulesContents = rulesFile.readAll();
+ QByteArray rulesContents = reader.data();
const QByteArray comment("# Uncomment this line for use without Qt Creator");
rulesContents.replace("DESTDIR", "INSTALL_ROOT");
rulesContents.replace("dh_shlibdeps", "# dh_shlibdeps " + comment);
// because dpkg-genchanges doesn't know about it (and can't be told).
// rulesContents.replace("dh_builddeb", "dh_builddeb --destdir=.");
- rulesFile.resize(0);
- rulesFile.write(rulesContents);
- rulesFile.close();
- if (rulesFile.error() != QFile::NoError) {
- raiseError(tr("Packaging Error: Cannot write file '%1'.")
- .arg(QDir::toNativeSeparators(rulesFilePath())));
+ Utils::FileSaver saver(rulesFilePath());
+ saver.write(rulesContents);
+ if (!saver.finalize()) {
+ raiseError(saver.errorString());
return false;
}
return true;
bool AbstractDebBasedQt4MaemoTarget::adaptControlFile()
{
- QFile controlFile(controlFilePath());
- if (!controlFile.open(QIODevice::ReadWrite)) {
- raiseError(tr("Packaging Error: Cannot open file '%1'.")
- .arg(QDir::toNativeSeparators(controlFilePath())));
+ Utils::FileReader reader;
+ if (!reader.fetch(controlFilePath())) {
+ raiseError(reader.errorString());
return false;
}
-
- QByteArray controlContents = controlFile.readAll();
+ QByteArray controlContents = reader.data();
adaptControlFileField(controlContents, "Section", defaultSection());
adaptControlFileField(controlContents, "Priority", "optional");
}
addAdditionalControlFileFields(controlContents);
- controlFile.resize(0);
- controlFile.write(controlContents);
- controlFile.close();
- if (controlFile.error() != QFile::NoError) {
- raiseError(tr("Packaging Error: Cannot write file '%1'.")
- .arg(QDir::toNativeSeparators(controlFilePath())));
+ Utils::FileSaver saver(controlFilePath());
+ saver.write(controlContents);
+ if (!saver.finalize()) {
+ raiseError(saver.errorString());
return false;
}
return true;
QByteArray AbstractRpmBasedQt4MaemoTarget::getValueForTag(const QByteArray &tag,
QString *error) const
{
- QSharedPointer<QFile> specFile
- = openFile(specFilePath(), QIODevice::ReadOnly, error);
- if (!specFile)
+ Utils::FileReader reader;
+ if (!reader.fetch(specFilePath(), error))
return QByteArray();
- const QByteArray &content = specFile->readAll();
+ const QByteArray &content = reader.data();
const QByteArray completeTag = tag.toLower() + ':';
int index = content.toLower().indexOf(completeTag);
if (index == -1)
bool AbstractRpmBasedQt4MaemoTarget::setValueForTag(const QByteArray &tag,
const QByteArray &value, QString *error)
{
- QSharedPointer<QFile> specFile
- = openFile(specFilePath(), QIODevice::ReadWrite, error);
- if (!specFile)
+ Utils::FileReader reader;
+ if (!reader.fetch(specFilePath(), error))
return false;
- QByteArray content = specFile->readAll();
+ QByteArray content = reader.data();
if (adaptTagValue(content, tag, value, false)) {
- specFile->resize(0);
- specFile->write(content);
+ Utils::FileSaver saver(specFilePath());
+ saver.write(content);
+ return saver.finalize(error);
}
return true;
}