Merge pull request #15419 from Chocobo1/file

Improve error detection when saving files
This commit is contained in:
Chocobo1
2021-09-19 13:28:47 +08:00
committed by GitHub
17 changed files with 2610 additions and 104 deletions

View File

@@ -28,7 +28,6 @@
#include "torrentinfo.h"
#include <libtorrent/bencode.hpp>
#include <libtorrent/create_torrent.hpp>
#include <libtorrent/error_code.hpp>
@@ -175,14 +174,9 @@ void TorrentInfo::saveToFile(const QString &path) const
{
const auto torrentCreator = lt::create_torrent(*nativeInfo());
const lt::entry torrentEntry = torrentCreator.generate();
QFile torrentFile {path};
if (!torrentFile.open(QIODevice::WriteOnly))
throw RuntimeError(torrentFile.errorString());
lt::bencode(Utils::IO::FileDeviceOutputIterator {torrentFile}, torrentEntry);
if (torrentFile.error() != QFileDevice::NoError)
throw RuntimeError(torrentFile.errorString());
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(path, torrentEntry);
if (!result)
throw RuntimeError(result.error());
}
catch (const lt::system_error &err)
{