NOISSUE use FS a bit more

This commit is contained in:
Petr Mrázek 2015-06-03 21:10:28 +02:00
parent 3a8b238052
commit 06a67fbd38
5 changed files with 36 additions and 59 deletions

View File

@ -30,6 +30,7 @@
#include "SeparatorPrefixTree.h"
#include "Env.h"
#include <icons/IconList.h>
#include <FileSystem.h>
class PackIgnoreProxy : public QSortFilterProxyModel
{
@ -469,15 +470,16 @@ void ExportInstanceDialog::loadPackIgnore()
void ExportInstanceDialog::savePackIgnore()
{
auto filename = ignoreFileName();
QSaveFile ignoreFile(filename);
if(!ignoreFile.open(QIODevice::WriteOnly))
{
ignoreFile.cancelWriting();
}
auto data = proxyModel->blockedPaths().toStringList().join('\n').toUtf8();
ignoreFile.write(data);
ignoreFile.commit();
auto filename = ignoreFileName();
try
{
FS::write(filename, data);
}
catch (Exception & e)
{
qWarning() << e.cause();
}
}
#include "ExportInstanceDialog.moc"

View File

@ -16,12 +16,12 @@
#include "BaseConfigObject.h"
#include <QTimer>
#include <QSaveFile>
#include <QFile>
#include <QCoreApplication>
#include <QDebug>
#include "Exception.h"
#include "FileSystem.h"
BaseConfigObject::BaseConfigObject(const QString &filename)
: m_filename(filename)
@ -76,19 +76,13 @@ void BaseConfigObject::saveNow()
return;
}
QSaveFile file(m_filename);
if (!file.open(QFile::WriteOnly))
try
{
qWarning() << "Couldn't open" << m_filename << "for writing:" << file.errorString();
return;
FS::write(m_filename, doSave());
}
// cppcheck-suppress pureVirtualCall
file.write(doSave());
if (!file.commit())
catch (Exception & e)
{
qCritical() << "Unable to commit the file" << file.fileName() << ":" << file.errorString();
file.cancelWriting();
qCritical() << e.cause();
}
}
void BaseConfigObject::loadNow()
@ -98,19 +92,9 @@ void BaseConfigObject::loadNow()
saveNow();
}
QFile file(m_filename);
if (!file.exists())
{
return;
}
if (!file.open(QFile::ReadOnly))
{
qWarning() << "Couldn't open" << m_filename << "for reading:" << file.errorString();
return;
}
try
{
doLoad(file.readAll());
doLoad(FS::read(m_filename));
}
catch (Exception & e)
{

View File

@ -3,7 +3,6 @@
#include "Json.h"
#include <QFile>
#include <QSaveFile>
#include "FileSystem.h"
#include <math.h>

View File

@ -15,12 +15,12 @@
#include "Env.h"
#include "HttpMetaCache.h"
#include "FileSystem.h"
#include <pathutils.h>
#include <QFileInfo>
#include <QFile>
#include <QTemporaryFile>
#include <QSaveFile>
#include <QDateTime>
#include <QCryptographicHash>
@ -230,9 +230,6 @@ void HttpMetaCache::SaveEventually()
void HttpMetaCache::SaveNow()
{
QSaveFile tfile(m_index_file);
if (!tfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
return;
QJsonObject toplevel;
toplevel.insert("version", QJsonValue(QString("1")));
QJsonArray entriesArr;
@ -259,12 +256,14 @@ void HttpMetaCache::SaveNow()
}
}
toplevel.insert("entries", entriesArr);
QJsonDocument doc(toplevel);
QByteArray jsonData = doc.toJson();
qint64 result = tfile.write(jsonData);
if (result == -1)
return;
if (result != jsonData.size())
return;
tfile.commit();
try
{
FS::write(m_index_file, doc.toJson());
}
catch (Exception & e)
{
qWarning() << e.what();
}
}

View File

@ -14,6 +14,7 @@
*/
#include "settings/INIFile.h"
#include <FileSystem.h>
#include <QFile>
#include <QTextStream>
@ -74,14 +75,7 @@ QString INIFile::escape(QString orig)
bool INIFile::saveFile(QString fileName)
{
QSaveFile file(fileName);
if(!file.open(QIODevice::WriteOnly))
{
qCritical() << "Unable to open INI config file" << fileName << "for saving";
return false;
}
QByteArray outArray;
for (Iterator iter = begin(); iter != end(); iter++)
{
QString value = iter.value().toString();
@ -91,18 +85,17 @@ bool INIFile::saveFile(QString fileName)
outArray.append(value.toUtf8());
outArray.append('\n');
}
if(file.write(outArray) != outArray.size())
try
{
qCritical() << "Unable to write to the INI config file" << fileName;
file.cancelWriting();
return false;
}
if(!file.commit())
{
qCritical() << "Unable to commit the INI config file" << fileName;
file.cancelWriting();
FS::write(fileName, outArray);
}
catch (Exception & e)
{
qCritical() << e.what();
return false;
}
return true;
}