mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-31 20:58:07 -06:00
Use QSaveFile wherever applicable
expected.hpp was fetched from:
b803e3c07b/include/nonstd/expected.hpp
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/gzip.h"
|
||||
#include "base/utils/io.h"
|
||||
#include "base/utils/misc.h"
|
||||
|
||||
const int MAX_REDIRECTIONS = 20; // the common value for web browsers
|
||||
@@ -43,12 +44,7 @@ namespace
|
||||
bool saveToFile(const QByteArray &replyData, QString &filePath)
|
||||
{
|
||||
if (!filePath.isEmpty())
|
||||
{
|
||||
QFile file {filePath};
|
||||
if (!file.open(QIODevice::WriteOnly))
|
||||
return false;
|
||||
return (file.write(replyData) == replyData.length());
|
||||
}
|
||||
return Utils::IO::saveToFile(filePath, replyData).has_value();
|
||||
|
||||
QTemporaryFile tmpfile {Utils::Fs::tempPath() + "XXXXXX"};
|
||||
tmpfile.setAutoRemove(false);
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QHostAddress>
|
||||
#include <QLocale>
|
||||
|
||||
@@ -40,6 +39,7 @@
|
||||
#include "base/profile.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/gzip.h"
|
||||
#include "base/utils/io.h"
|
||||
#include "downloadmanager.h"
|
||||
#include "geoipdatabase.h"
|
||||
|
||||
@@ -452,15 +452,16 @@ void GeoIPManager::downloadFinished(const DownloadResult &result)
|
||||
if (!QDir(targetPath).exists())
|
||||
QDir().mkpath(targetPath);
|
||||
|
||||
QFile targetFile(QString::fromLatin1("%1/%2").arg(targetPath, GEODB_FILENAME));
|
||||
if (!targetFile.open(QFile::WriteOnly) || (targetFile.write(data) != data.length()))
|
||||
const auto path = QString::fromLatin1("%1/%2").arg(targetPath, GEODB_FILENAME);
|
||||
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(path, data);
|
||||
if (result)
|
||||
{
|
||||
LogMsg(tr("Couldn't save downloaded IP geolocation database file. Reason: %1")
|
||||
.arg(targetFile.errorString()), Log::WARNING);
|
||||
LogMsg(tr("Successfully updated IP geolocation database."), Log::INFO);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMsg(tr("Successfully updated IP geolocation database."), Log::INFO);
|
||||
LogMsg(tr("Couldn't save downloaded IP geolocation database file. Reason: %1")
|
||||
.arg(result.error()), Log::WARNING);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user