mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-21 07:57:22 -06:00
Merge pull request #15419 from Chocobo1/file
Improve error detection when saving files
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user