mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 21:14:33 +00:00
Improve error detection when saving files
This commit is contained in:
parent
6a6268c068
commit
81139c0098
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user