Browse Source

Improve error detection when saving files

adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
81139c0098
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 2
      src/app/upgrade.cpp
  2. 13
      src/base/asyncfilestorage.cpp
  3. 8
      src/base/net/downloadhandlerimpl.cpp
  4. 10
      src/base/net/geoipmanager.cpp
  5. 11
      src/gui/rss/automatedrssdownloader.cpp

2
src/app/upgrade.cpp

@ -63,7 +63,7 @@ namespace
{ {
file.close(); file.close();
Utils::Fs::forceRemove(savePath); Utils::Fs::forceRemove(savePath);
LogMsg(errorMsgFormat.arg(savePath, QLatin1String("Write incomplete.")) , Log::WARNING); LogMsg(errorMsgFormat.arg(savePath, QObject::tr("Write incomplete")) , Log::WARNING);
return; return;
} }

13
src/base/asyncfilestorage.cpp

@ -67,15 +67,12 @@ QDir AsyncFileStorage::storageDir() const
void AsyncFileStorage::store_impl(const QString &fileName, const QByteArray &data) void AsyncFileStorage::store_impl(const QString &fileName, const QByteArray &data)
{ {
const QString filePath = m_storageDir.absoluteFilePath(fileName); const QString filePath = m_storageDir.absoluteFilePath(fileName);
QSaveFile file(filePath);
qDebug() << "AsyncFileStorage: Saving data to" << filePath; qDebug() << "AsyncFileStorage: Saving data to" << filePath;
if (file.open(QIODevice::WriteOnly))
QSaveFile file(filePath);
if (!file.open(QIODevice::WriteOnly) || (file.write(data) != data.length()) || !file.commit())
{ {
file.write(data); qDebug() << "AsyncFileStorage: Failed to save data";
if (!file.commit()) emit failed(filePath, file.errorString());
{
qDebug() << "AsyncFileStorage: Failed to save data";
emit failed(filePath, file.errorString());
}
} }
} }

8
src/base/net/downloadhandlerimpl.cpp

@ -47,9 +47,7 @@ namespace
QFile file {filePath}; QFile file {filePath};
if (!file.open(QIODevice::WriteOnly)) if (!file.open(QIODevice::WriteOnly))
return false; return false;
return (file.write(replyData) == replyData.length());
file.write(replyData);
return true;
} }
QTemporaryFile tmpfile {Utils::Fs::tempPath() + "XXXXXX"}; QTemporaryFile tmpfile {Utils::Fs::tempPath() + "XXXXXX"};
@ -59,9 +57,7 @@ namespace
return false; return false;
filePath = tmpfile.fileName(); filePath = tmpfile.fileName();
return (tmpfile.write(replyData) == replyData.length());
tmpfile.write(replyData);
return true;
} }
} }

10
src/base/net/geoipmanager.cpp

@ -451,11 +451,17 @@ void GeoIPManager::downloadFinished(const DownloadResult &result)
specialFolderLocation(SpecialFolder::Data) + GEODB_FOLDER); specialFolderLocation(SpecialFolder::Data) + GEODB_FOLDER);
if (!QDir(targetPath).exists()) if (!QDir(targetPath).exists())
QDir().mkpath(targetPath); QDir().mkpath(targetPath);
QFile targetFile(QString::fromLatin1("%1/%2").arg(targetPath, GEODB_FILENAME)); QFile targetFile(QString::fromLatin1("%1/%2").arg(targetPath, GEODB_FILENAME));
if (!targetFile.open(QFile::WriteOnly) || (targetFile.write(data) == -1)) if (!targetFile.open(QFile::WriteOnly) || (targetFile.write(data) != data.length()))
LogMsg(tr("Couldn't save downloaded IP geolocation database file."), Log::WARNING); {
LogMsg(tr("Couldn't save downloaded IP geolocation database file. Reason: %1")
.arg(targetFile.errorString()), Log::WARNING);
}
else else
{
LogMsg(tr("Successfully updated IP geolocation database."), Log::INFO); LogMsg(tr("Successfully updated IP geolocation database."), Log::INFO);
}
} }
else else
{ {

11
src/gui/rss/automatedrssdownloader.cpp

@ -452,13 +452,12 @@ void AutomatedRssDownloader::on_exportBtn_clicked()
path += EXT_LEGACY; path += EXT_LEGACY;
} }
const QByteArray rules {RSS::AutoDownloader::instance()->exportRules(format)};
QFile file {path}; QFile file {path};
if (!file.open(QFile::WriteOnly) if (!file.open(QFile::WriteOnly) || (file.write(rules) != rules.length()))
|| (file.write(RSS::AutoDownloader::instance()->exportRules(format)) == -1)) {
{ QMessageBox::critical(this, tr("I/O Error")
QMessageBox::critical( , tr("Failed to create the destination file. Reason: %1").arg(file.errorString()));
this, tr("I/O Error")
, tr("Failed to create the destination file. Reason: %1").arg(file.errorString()));
} }
} }

Loading…
Cancel
Save