2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2021-12-25 21:21:13 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
2022-08-17 16:08:36 +00:00
|
|
|
#include <cerrno> // for EINVAL
|
2023-11-21 15:02:03 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
2021-12-25 21:21:13 +00:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-03-14 04:43:35 +00:00
|
|
|
#include <fmt/core.h>
|
|
|
|
|
2023-04-14 19:33:23 +00:00
|
|
|
#include "libtransmission/transmission.h"
|
|
|
|
|
|
|
|
#include "libtransmission/benc.h"
|
|
|
|
#include "libtransmission/crypto-utils.h"
|
|
|
|
#include "libtransmission/error.h"
|
|
|
|
#include "libtransmission/file.h"
|
|
|
|
#include "libtransmission/log.h"
|
2023-11-21 15:02:03 +00:00
|
|
|
#include "libtransmission/torrent-files.h"
|
2023-04-14 19:33:23 +00:00
|
|
|
#include "libtransmission/torrent-metainfo.h"
|
|
|
|
#include "libtransmission/tr-assert.h"
|
2023-11-21 15:02:03 +00:00
|
|
|
#include "libtransmission/tr-macros.h"
|
2023-04-14 19:33:23 +00:00
|
|
|
#include "libtransmission/tr-strbuf.h"
|
|
|
|
#include "libtransmission/utils.h"
|
2021-12-25 21:21:13 +00:00
|
|
|
|
|
|
|
using namespace std::literals;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Ensure that the URLs for multfile torrents end in a slash.
|
|
|
|
*
|
|
|
|
* See http://bittorrent.org/beps/bep_0019.html#metadata-extension
|
|
|
|
* for background on how the trailing slash is used for "url-list"
|
|
|
|
* fields.
|
|
|
|
*
|
|
|
|
* This function is to workaround some .torrent generators, such as
|
|
|
|
* mktorrent and very old versions of utorrent, that don't add the
|
|
|
|
* trailing slash for multifile torrents if omitted by the end user.
|
|
|
|
*/
|
2023-04-23 01:25:55 +00:00
|
|
|
std::string tr_torrent_metainfo::fix_webseed_url(tr_torrent_metainfo const& tm, std::string_view url)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2023-06-30 14:49:58 +00:00
|
|
|
url = tr_strv_strip(url);
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
if (tm.file_count() > 1U && !std::empty(url) && url.back() != '/')
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
|
|
|
return std::string{ url } + '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::string{ url };
|
|
|
|
}
|
|
|
|
|
2023-01-27 20:25:08 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
auto constexpr MaxBencDepth = 32;
|
|
|
|
} // namespace
|
2022-05-24 04:05:16 +00:00
|
|
|
|
|
|
|
struct MetainfoHandler final : public transmission::benc::BasicHandler<MaxBencDepth>
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
using BasicHandler = transmission::benc::BasicHandler<MaxBencDepth>;
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
tr_torrent_metainfo& tm_;
|
2023-12-06 04:06:27 +00:00
|
|
|
uint32_t piece_size_ = {};
|
2022-05-24 04:05:16 +00:00
|
|
|
int64_t length_ = 0;
|
|
|
|
std::string encoding_ = "UTF-8";
|
|
|
|
std::string_view info_dict_begin_;
|
|
|
|
tr_tracker_tier_t tier_ = 0;
|
|
|
|
tr_pathbuf file_subpath_;
|
|
|
|
std::string_view pieces_root_;
|
|
|
|
int64_t file_length_ = 0;
|
|
|
|
|
2024-01-08 14:32:58 +00:00
|
|
|
enum class State : uint8_t
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
UsePath,
|
|
|
|
FileTree,
|
|
|
|
Files,
|
|
|
|
FilesIgnored,
|
|
|
|
PieceLayers,
|
|
|
|
};
|
|
|
|
State state_ = State::UsePath;
|
|
|
|
|
|
|
|
explicit MetainfoHandler(tr_torrent_metainfo& tm)
|
|
|
|
: tm_{ tm }
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
bool Key(std::string_view key, Context const& context) override
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
return BasicHandler::Key(key, context);
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
bool StartDict(Context const& context) override
|
|
|
|
{
|
|
|
|
if (state_ == State::FileTree)
|
|
|
|
{
|
|
|
|
if (!std::empty(file_subpath_))
|
|
|
|
{
|
|
|
|
file_subpath_ += '/';
|
|
|
|
}
|
|
|
|
tr_torrent_files::makeSubpathPortable(currentKey(), file_subpath_);
|
|
|
|
}
|
|
|
|
else if (pathIs(InfoKey))
|
|
|
|
{
|
|
|
|
info_dict_begin_ = context.raw();
|
|
|
|
tm_.info_dict_offset_ = context.tokenSpan().first;
|
|
|
|
}
|
|
|
|
else if (pathIs(InfoKey, FileTreeKey))
|
|
|
|
{
|
|
|
|
state_ = State::FileTree;
|
|
|
|
file_subpath_.clear();
|
|
|
|
file_length_ = 0;
|
|
|
|
}
|
|
|
|
else if (pathIs(PieceLayersKey))
|
|
|
|
{
|
|
|
|
state_ = State::PieceLayers;
|
|
|
|
}
|
|
|
|
|
|
|
|
return BasicHandler::StartDict(context);
|
|
|
|
}
|
2022-02-23 23:38:07 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
bool EndDict(Context const& context) override
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
BasicHandler::EndDict(context);
|
2022-02-23 23:38:07 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
if (pathIs(InfoKey))
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
return finishInfoDict(context);
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
if (depth() == 0) // top
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
return finish(context);
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
if (state_ == State::FileTree) // bittorrent v2 format
|
|
|
|
{
|
2022-07-02 17:16:34 +00:00
|
|
|
// v2, ignore for today
|
|
|
|
tr_logAddInfo("'file tree' is ignored");
|
2022-07-14 18:53:00 +00:00
|
|
|
state_ = State::UsePath;
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
else if (state_ == State::Files) // bittorrent v1 format
|
|
|
|
{
|
|
|
|
if (!addFile(context))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
file_subpath_.clear();
|
|
|
|
}
|
2022-07-14 18:53:00 +00:00
|
|
|
else if (state_ == State::PieceLayers)
|
|
|
|
{
|
|
|
|
state_ = State::UsePath;
|
|
|
|
}
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
return depth() > 0;
|
|
|
|
}
|
2022-02-23 23:38:07 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
bool StartArray(Context const& context) override
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
if (pathIs(InfoKey, FilesKey))
|
|
|
|
{
|
|
|
|
state_ = std::empty(tm_.files_) ? State::Files : State::FilesIgnored;
|
|
|
|
file_subpath_.clear();
|
|
|
|
file_length_ = 0;
|
|
|
|
}
|
2023-03-13 18:58:59 +00:00
|
|
|
else if (pathStartsWith(InfoKey, FilesKey, ""sv, PathUtf8Key))
|
|
|
|
{
|
|
|
|
// torrent has a utf8 path, drop the other one due to probable non-utf8 encoding
|
|
|
|
file_subpath_.clear();
|
|
|
|
}
|
2022-05-24 04:05:16 +00:00
|
|
|
|
|
|
|
return BasicHandler::StartArray(context);
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
bool EndArray(Context const& context) override
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
BasicHandler::EndArray(context);
|
|
|
|
|
|
|
|
if ((state_ == State::Files || state_ == State::FilesIgnored) && currentKey() == FilesKey) // bittorrent v1 format
|
|
|
|
{
|
|
|
|
state_ = State::UsePath;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (depth() == 2 && key(1) == AnnounceListKey)
|
|
|
|
{
|
|
|
|
++tier_;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
bool Int64(int64_t value, Context const& /*context*/) override
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2024-02-13 16:42:19 +00:00
|
|
|
auto unhandled = false;
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
if (state_ == State::FilesIgnored)
|
|
|
|
{
|
|
|
|
// no-op
|
|
|
|
}
|
|
|
|
else if (state_ == State::FileTree || state_ == State::Files)
|
|
|
|
{
|
|
|
|
if (currentKey() == LengthKey)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
file_length_ = value;
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
2022-05-24 04:05:16 +00:00
|
|
|
else if (pathIs(InfoKey, FilesKey, ""sv, MtimeKey))
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
// unused by Transmission
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
2022-05-24 04:05:16 +00:00
|
|
|
else
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
unhandled = true;
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-24 20:28:02 +00:00
|
|
|
else if (pathIs(CreationDateKey) || pathIs(InfoKey, CreationDateKey))
|
2022-05-24 04:05:16 +00:00
|
|
|
{
|
|
|
|
tm_.date_created_ = value;
|
|
|
|
}
|
|
|
|
else if (pathIs(PrivateKey) || pathIs(InfoKey, PrivateKey))
|
|
|
|
{
|
|
|
|
tm_.is_private_ = value != 0;
|
|
|
|
}
|
|
|
|
else if (pathIs(PieceLengthKey) || pathIs(InfoKey, PieceLengthKey))
|
|
|
|
{
|
2023-12-06 04:06:27 +00:00
|
|
|
piece_size_ = static_cast<uint32_t>(value);
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
else if (pathIs(InfoKey, LengthKey))
|
|
|
|
{
|
|
|
|
length_ = value;
|
|
|
|
}
|
|
|
|
else if (pathIs(InfoKey, MetaVersionKey))
|
|
|
|
{
|
|
|
|
// currently unused. TODO support for bittorrent v2
|
|
|
|
// TODO https://github.com/transmission/transmission/issues/458
|
2022-07-01 14:49:33 +00:00
|
|
|
tm_.is_v2_ = value == 2;
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
else if (
|
2022-05-24 20:28:02 +00:00
|
|
|
pathIs(DurationKey) || //
|
|
|
|
pathIs(EncodedRateKey) || //
|
|
|
|
pathIs(HeightKey) || //
|
|
|
|
pathIs(InfoKey, EntropyKey) || //
|
|
|
|
pathIs(InfoKey, UniqueKey) || //
|
|
|
|
pathIs(ProfilesKey, HeightKey) || //
|
|
|
|
pathIs(ProfilesKey, WidthKey) || //
|
|
|
|
pathIs(WidthKey) || //
|
|
|
|
pathStartsWith(AzureusPropertiesKey) || //
|
|
|
|
pathStartsWith(InfoKey, FileDurationKey) || //
|
|
|
|
pathStartsWith(InfoKey, FileMediaKey) || //
|
|
|
|
pathStartsWith(InfoKey, ProfilesKey) || //
|
2023-03-13 18:58:59 +00:00
|
|
|
pathStartsWith(LibtorrentResumeKey) || //
|
|
|
|
pathStartsWith(NodesKey))
|
2022-05-24 04:05:16 +00:00
|
|
|
{
|
|
|
|
// unused by Transmission
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unhandled = true;
|
|
|
|
}
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
if (unhandled)
|
|
|
|
{
|
|
|
|
tr_logAddWarn(fmt::format("unexpected: path '{}', int '{}'", path(), value));
|
|
|
|
}
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
bool String(std::string_view value, Context const& context) override
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
auto const curdepth = depth();
|
|
|
|
auto const current_key = currentKey();
|
2024-02-13 16:42:19 +00:00
|
|
|
auto unhandled = false;
|
2022-05-24 04:05:16 +00:00
|
|
|
|
|
|
|
if (state_ == State::FilesIgnored)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
// no-op
|
|
|
|
}
|
|
|
|
else if (state_ == State::FileTree)
|
|
|
|
{
|
|
|
|
if (current_key == AttrKey || current_key == PiecesRootKey)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
// currently unused. TODO support for bittorrent v2
|
|
|
|
// TODO https://github.com/transmission/transmission/issues/458
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
2022-05-24 04:05:16 +00:00
|
|
|
else
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
unhandled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (state_ == State::Files)
|
|
|
|
{
|
2023-03-13 18:58:59 +00:00
|
|
|
if (curdepth > 1 && (key(curdepth - 1) == PathKey || key(curdepth - 1) == PathUtf8Key))
|
2022-05-24 04:05:16 +00:00
|
|
|
{
|
|
|
|
if (!std::empty(file_subpath_))
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
file_subpath_ += '/';
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
2022-05-24 04:05:16 +00:00
|
|
|
tr_torrent_files::makeSubpathPortable(value, file_subpath_);
|
|
|
|
}
|
|
|
|
else if (current_key == AttrKey)
|
|
|
|
{
|
|
|
|
// currently unused. TODO support for bittorrent v2
|
|
|
|
// TODO https://github.com/transmission/transmission/issues/458
|
|
|
|
}
|
2022-05-24 20:28:02 +00:00
|
|
|
else if (
|
|
|
|
pathIs(InfoKey, FilesKey, ""sv, Crc32Key) || //
|
|
|
|
pathIs(InfoKey, FilesKey, ""sv, Ed2kKey) || //
|
2022-06-01 21:14:09 +00:00
|
|
|
pathIs(InfoKey, FilesKey, ""sv, FilehashKey) || //
|
2022-05-24 20:28:02 +00:00
|
|
|
pathIs(InfoKey, FilesKey, ""sv, Md5Key) || //
|
|
|
|
pathIs(InfoKey, FilesKey, ""sv, Md5sumKey) || //
|
|
|
|
pathIs(InfoKey, FilesKey, ""sv, MtimeKey) || // (why a string?)
|
2023-03-13 18:58:59 +00:00
|
|
|
pathIs(InfoKey, FilesKey, ""sv, Sha1Key))
|
2022-05-24 20:28:02 +00:00
|
|
|
{
|
|
|
|
// unused by Transmission
|
|
|
|
}
|
2022-05-24 04:05:16 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unhandled = true;
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-24 04:05:16 +00:00
|
|
|
else if (pathIs(CommentKey) || pathIs(CommentUtf8Key))
|
|
|
|
{
|
2023-03-19 15:36:16 +00:00
|
|
|
tm_.comment_ = tr_strv_convert_utf8(value);
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
else if (pathIs(CreatedByKey) || pathIs(CreatedByUtf8Key))
|
|
|
|
{
|
2023-03-19 15:36:16 +00:00
|
|
|
tm_.creator_ = tr_strv_convert_utf8(value);
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
2023-03-13 18:58:59 +00:00
|
|
|
else if (
|
|
|
|
pathIs(SourceKey) || pathIs(InfoKey, SourceKey) || //
|
|
|
|
pathIs(PublisherKey) || pathIs(InfoKey, PublisherKey) || //
|
|
|
|
pathIs(PublisherUtf8Key) || pathIs(InfoKey, PublisherUtf8Key))
|
2022-05-24 04:05:16 +00:00
|
|
|
{
|
|
|
|
// “publisher” is rare, but used by BitComet and appears
|
|
|
|
// to have the same use as the 'source' key
|
|
|
|
// http://wiki.bitcomet.com/inside_bitcomet
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2023-03-19 15:36:16 +00:00
|
|
|
tm_.source_ = tr_strv_convert_utf8(value);
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
else if (pathIs(AnnounceKey))
|
|
|
|
{
|
2023-04-23 01:25:55 +00:00
|
|
|
tm_.announce_list().add(value, tier_);
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
else if (pathIs(EncodingKey))
|
|
|
|
{
|
2023-06-30 14:49:58 +00:00
|
|
|
encoding_ = tr_strv_strip(value);
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
else if (pathIs(UrlListKey))
|
|
|
|
{
|
2023-04-23 01:25:55 +00:00
|
|
|
tm_.add_webseed(value);
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
else if (pathIs(InfoKey, NameKey) || pathIs(InfoKey, NameUtf8Key))
|
|
|
|
{
|
2023-04-23 01:25:55 +00:00
|
|
|
tm_.set_name(value);
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
else if (pathIs(InfoKey, PiecesKey))
|
|
|
|
{
|
2022-08-09 22:04:56 +00:00
|
|
|
if (std::size(value) % sizeof(tr_sha1_digest_t) == 0)
|
|
|
|
{
|
|
|
|
auto const n = std::size(value) / sizeof(tr_sha1_digest_t);
|
|
|
|
tm_.pieces_.resize(n);
|
|
|
|
std::copy_n(std::data(value), std::size(value), reinterpret_cast<char*>(std::data(tm_.pieces_)));
|
|
|
|
tm_.pieces_offset_ = context.tokenSpan().first;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-11-04 16:39:41 +00:00
|
|
|
context.error.set(EINVAL, fmt::format("invalid piece size: {}", std::size(value)));
|
2022-08-09 22:04:56 +00:00
|
|
|
unhandled = true;
|
|
|
|
}
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
else if (pathStartsWith(PieceLayersKey))
|
|
|
|
{
|
|
|
|
// currently unused. TODO support for bittorrent v2
|
|
|
|
// TODO https://github.com/transmission/transmission/issues/458
|
|
|
|
}
|
|
|
|
else if (pathStartsWith(AnnounceListKey))
|
|
|
|
{
|
2023-04-23 01:25:55 +00:00
|
|
|
tm_.announce_list().add(value, tier_);
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
else if (curdepth == 2 && (pathStartsWith(HttpSeedsKey) || pathStartsWith(UrlListKey)))
|
|
|
|
{
|
2023-04-23 01:25:55 +00:00
|
|
|
tm_.add_webseed(value);
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
2023-04-12 22:26:43 +00:00
|
|
|
else if (pathIs(MagnetInfoKey, DisplayNameKey) && std::empty(tm_.name()))
|
2023-02-13 00:10:54 +00:00
|
|
|
{
|
|
|
|
// compatibility with Transmission <= 3.0
|
2023-04-23 01:25:55 +00:00
|
|
|
tm_.set_name(value);
|
2023-02-13 00:10:54 +00:00
|
|
|
}
|
|
|
|
else if (pathIs(MagnetInfoKey, InfoHashKey))
|
|
|
|
{
|
|
|
|
// compatibility with Transmission <= 3.0
|
|
|
|
if (value.length() == sizeof(tr_sha1_digest_t))
|
|
|
|
{
|
|
|
|
std::copy_n(std::data(value), sizeof(tr_sha1_digest_t), reinterpret_cast<char*>(std::data(tm_.info_hash_)));
|
|
|
|
tm_.info_hash_str_ = tr_sha1_to_string(tm_.info_hash_);
|
|
|
|
tm_.has_magnet_info_hash_ = true;
|
|
|
|
}
|
|
|
|
}
|
2022-05-24 20:28:02 +00:00
|
|
|
else if (
|
|
|
|
pathIs(ChecksumKey) || //
|
|
|
|
pathIs(ErrCallbackKey) || //
|
2023-04-10 16:07:43 +00:00
|
|
|
pathIs(InfoKey, CrossSeedEntryKey) || //
|
2022-05-24 20:28:02 +00:00
|
|
|
pathIs(InfoKey, Ed2kKey) || //
|
|
|
|
pathIs(InfoKey, EntropyKey) || //
|
|
|
|
pathIs(InfoKey, Md5sumKey) || //
|
|
|
|
pathIs(InfoKey, PublisherUrlKey) || //
|
2023-03-13 18:58:59 +00:00
|
|
|
pathIs(InfoKey, PublisherUrlUtf8Key) || //
|
2022-05-24 20:28:02 +00:00
|
|
|
pathIs(InfoKey, Sha1Key) || //
|
|
|
|
pathIs(InfoKey, UniqueKey) || //
|
|
|
|
pathIs(InfoKey, XCrossSeedKey) || //
|
|
|
|
pathIs(LocaleKey) || //
|
|
|
|
pathIs(LogCallbackKey) || //
|
|
|
|
pathIs(PublisherUrlKey) || //
|
2023-03-13 18:58:59 +00:00
|
|
|
pathIs(PublisherUrlUtf8Key) || //
|
2022-05-24 20:28:02 +00:00
|
|
|
pathIs(TitleKey) || //
|
2023-04-10 16:07:43 +00:00
|
|
|
pathIs(UidKey) || //
|
2022-05-24 20:28:02 +00:00
|
|
|
pathStartsWith(AzureusPrivatePropertiesKey) || //
|
|
|
|
pathStartsWith(AzureusPropertiesKey) || //
|
|
|
|
pathStartsWith(InfoKey, CollectionsKey) || //
|
|
|
|
pathStartsWith(InfoKey, FileDurationKey) || //
|
|
|
|
pathStartsWith(InfoKey, ProfilesKey) || //
|
|
|
|
pathStartsWith(LibtorrentResumeKey) || //
|
2023-03-13 18:58:59 +00:00
|
|
|
pathStartsWith(MagnetInfoKey) || //
|
|
|
|
pathStartsWith(NodesKey))
|
2022-05-24 20:28:02 +00:00
|
|
|
{
|
|
|
|
// unused by Transmission
|
|
|
|
}
|
2022-05-24 04:05:16 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unhandled = true;
|
|
|
|
}
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
if (unhandled)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
tr_logAddWarn(fmt::format("unexpected: path '{}', str '{}'", path(), value));
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
return true;
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
private:
|
|
|
|
template<typename... Args>
|
|
|
|
[[nodiscard]] bool pathStartsWith(Args... args) const noexcept
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
auto i = 1U;
|
|
|
|
return (depth() >= sizeof...(args)) && ((key(i++) == args) && ...);
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
template<typename... Args>
|
|
|
|
[[nodiscard]] bool pathIs(Args... args) const noexcept
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
auto i = 1U;
|
|
|
|
return (depth() == sizeof...(args)) && ((key(i++) == args) && ...);
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
[[nodiscard]] bool addFile(Context const& context)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
bool ok = true;
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
// FIXME: Check to see if we already added this file. This is a safeguard
|
|
|
|
// for hybrid torrents with duplicate info between "file tree" and "files"
|
|
|
|
if (std::empty(file_subpath_))
|
|
|
|
{
|
2023-11-04 16:39:41 +00:00
|
|
|
context.error.set(EINVAL, fmt::format("invalid path [{:s}]", file_subpath_));
|
2022-05-24 04:05:16 +00:00
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tm_.files_.add(file_subpath_, file_length_);
|
|
|
|
}
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
file_length_ = 0;
|
|
|
|
pieces_root_ = {};
|
|
|
|
// NB: let caller decide how to clear file_tree_.
|
|
|
|
// if we're in "files" mode we clear it; if in "file tree" we pop it
|
|
|
|
return ok;
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
bool finishInfoDict(Context const& context)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
if (std::empty(info_dict_begin_))
|
|
|
|
{
|
2023-11-04 16:39:41 +00:00
|
|
|
context.error.set(EINVAL, "no info_dict found");
|
2022-05-24 04:05:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
auto root = tr_pathbuf{};
|
|
|
|
tr_torrent_files::makeSubpathPortable(tm_.name_, root);
|
|
|
|
if (!std::empty(root))
|
|
|
|
{
|
|
|
|
tm_.files_.insertSubpathPrefix(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
TR_ASSERT(info_dict_begin_[0] == 'd');
|
|
|
|
TR_ASSERT(context.raw().back() == 'e');
|
|
|
|
char const* const begin = &info_dict_begin_.front();
|
|
|
|
char const* const end = &context.raw().back() + 1;
|
|
|
|
auto const info_dict_benc = std::string_view{ begin, size_t(end - begin) };
|
2022-07-31 20:58:14 +00:00
|
|
|
auto const hash = tr_sha1::digest(info_dict_benc);
|
|
|
|
auto const hash2 = tr_sha256::digest(info_dict_benc);
|
2022-06-01 16:56:59 +00:00
|
|
|
|
2022-07-31 20:58:14 +00:00
|
|
|
tm_.info_hash_ = hash;
|
2022-05-24 04:05:16 +00:00
|
|
|
tm_.info_hash_str_ = tr_sha1_to_string(tm_.info_hash_);
|
2022-07-31 20:58:14 +00:00
|
|
|
tm_.info_hash2_ = hash2;
|
2022-07-01 14:49:33 +00:00
|
|
|
tm_.info_hash2_str_ = tr_sha256_to_string(tm_.info_hash2_);
|
2022-05-24 04:05:16 +00:00
|
|
|
tm_.info_dict_size_ = std::size(info_dict_benc);
|
|
|
|
return true;
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
bool finish(Context const& context)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
// bittorrent 1.0 spec
|
|
|
|
// http://bittorrent.org/beps/bep_0003.html
|
|
|
|
//
|
|
|
|
// "There is also a key length or a key files, but not both or neither.
|
|
|
|
//
|
|
|
|
// "If length is present then the download represents a single file,
|
|
|
|
// otherwise it represents a set of files which go in a directory structure.
|
|
|
|
// In the single file case, length maps to the length of the file in bytes.
|
2023-04-23 01:25:55 +00:00
|
|
|
if (tm_.file_count() == 0 && length_ != 0 && !std::empty(tm_.name_))
|
2022-05-24 04:05:16 +00:00
|
|
|
{
|
|
|
|
tm_.files_.add(tm_.name_, length_);
|
|
|
|
}
|
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
if (auto const has_metainfo = tm_.info_dict_size() != 0U; has_metainfo)
|
2022-05-24 04:05:16 +00:00
|
|
|
{
|
2023-02-25 13:11:19 +00:00
|
|
|
// do some sanity checks to make sure the torrent looks sane
|
2023-04-23 01:25:55 +00:00
|
|
|
if (tm_.file_count() == 0)
|
2022-05-24 04:05:16 +00:00
|
|
|
{
|
2023-11-04 16:39:41 +00:00
|
|
|
if (!context.error)
|
2023-02-25 13:11:19 +00:00
|
|
|
{
|
2023-11-04 16:39:41 +00:00
|
|
|
context.error.set(EINVAL, "no files found");
|
2023-02-25 13:11:19 +00:00
|
|
|
}
|
|
|
|
return false;
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
|
2023-12-06 04:06:27 +00:00
|
|
|
if (piece_size_ == 0U)
|
2022-05-24 04:05:16 +00:00
|
|
|
{
|
2023-11-04 16:39:41 +00:00
|
|
|
if (!context.error)
|
2023-02-25 13:11:19 +00:00
|
|
|
{
|
2023-11-04 16:39:41 +00:00
|
|
|
context.error.set(EINVAL, fmt::format("invalid piece size: {}", piece_size_));
|
2023-02-25 13:11:19 +00:00
|
|
|
}
|
|
|
|
return false;
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
2023-02-25 13:11:19 +00:00
|
|
|
|
2023-12-06 04:06:27 +00:00
|
|
|
tm_.block_info_ = tr_block_info{ tm_.files_.totalSize(), piece_size_ };
|
2023-02-25 13:11:19 +00:00
|
|
|
return true;
|
2022-05-24 04:05:16 +00:00
|
|
|
}
|
|
|
|
|
2023-02-25 13:11:19 +00:00
|
|
|
// no metainfo; might be a Transmission 3.00-style magnet file
|
|
|
|
auto const ok = tm_.has_magnet_info_hash_;
|
|
|
|
return ok;
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view AcodecKey = "acodec"sv;
|
|
|
|
static constexpr std::string_view AnnounceKey = "announce"sv;
|
|
|
|
static constexpr std::string_view AnnounceListKey = "announce-list"sv;
|
|
|
|
static constexpr std::string_view AttrKey = "attr"sv;
|
2022-05-24 20:28:02 +00:00
|
|
|
static constexpr std::string_view AzureusPrivatePropertiesKey = "azureus_private_properties"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view AzureusPropertiesKey = "azureus_properties"sv;
|
|
|
|
static constexpr std::string_view ChecksumKey = "checksum"sv;
|
2022-05-24 20:28:02 +00:00
|
|
|
static constexpr std::string_view CollectionsKey = "collections"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view CommentKey = "comment"sv;
|
|
|
|
static constexpr std::string_view CommentUtf8Key = "comment.utf-8"sv;
|
2022-05-24 20:28:02 +00:00
|
|
|
static constexpr std::string_view Crc32Key = "crc32"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view CreatedByKey = "created by"sv;
|
|
|
|
static constexpr std::string_view CreatedByUtf8Key = "created by.utf-8"sv;
|
|
|
|
static constexpr std::string_view CreationDateKey = "creation date"sv;
|
2023-04-10 16:07:43 +00:00
|
|
|
static constexpr std::string_view CrossSeedEntryKey = "cross_seed_entry"sv;
|
2023-02-13 00:10:54 +00:00
|
|
|
static constexpr std::string_view DisplayNameKey = "display-name"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view DurationKey = "duration"sv;
|
2022-05-24 20:28:02 +00:00
|
|
|
static constexpr std::string_view Ed2kKey = "ed2k"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view EncodedRateKey = "encoded rate"sv;
|
|
|
|
static constexpr std::string_view EncodingKey = "encoding"sv;
|
|
|
|
static constexpr std::string_view EntropyKey = "entropy"sv;
|
2022-05-24 20:28:02 +00:00
|
|
|
static constexpr std::string_view ErrCallbackKey = "err_callback"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view FileDurationKey = "file-duration"sv;
|
|
|
|
static constexpr std::string_view FileMediaKey = "file-media"sv;
|
|
|
|
static constexpr std::string_view FileTreeKey = "file tree"sv;
|
2022-06-01 21:14:09 +00:00
|
|
|
static constexpr std::string_view FilehashKey = "filehash"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view FilesKey = "files"sv;
|
|
|
|
static constexpr std::string_view HeightKey = "height"sv;
|
|
|
|
static constexpr std::string_view HttpSeedsKey = "httpseeds"sv;
|
|
|
|
static constexpr std::string_view InfoKey = "info"sv;
|
2023-02-13 00:10:54 +00:00
|
|
|
static constexpr std::string_view InfoHashKey = "info_hash"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view LengthKey = "length"sv;
|
2022-05-24 20:28:02 +00:00
|
|
|
static constexpr std::string_view LibtorrentResumeKey = "libtorrent_resume"sv;
|
|
|
|
static constexpr std::string_view LocaleKey = "locale"sv;
|
|
|
|
static constexpr std::string_view LogCallbackKey = "log_callback"sv;
|
|
|
|
static constexpr std::string_view MagnetInfoKey = "magnet-info"sv;
|
|
|
|
static constexpr std::string_view Md5Key = "md5"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view Md5sumKey = "md5sum"sv;
|
|
|
|
static constexpr std::string_view MetaVersionKey = "meta version"sv;
|
|
|
|
static constexpr std::string_view MtimeKey = "mtime"sv;
|
|
|
|
static constexpr std::string_view NameKey = "name"sv;
|
|
|
|
static constexpr std::string_view NameUtf8Key = "name.utf-8"sv;
|
2023-03-13 18:58:59 +00:00
|
|
|
static constexpr std::string_view NodesKey = "nodes"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view PathKey = "path"sv;
|
2022-05-24 20:28:02 +00:00
|
|
|
static constexpr std::string_view PathUtf8Key = "path.utf-8"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view PieceLayersKey = "piece layers"sv;
|
|
|
|
static constexpr std::string_view PieceLengthKey = "piece length"sv;
|
|
|
|
static constexpr std::string_view PiecesKey = "pieces"sv;
|
|
|
|
static constexpr std::string_view PiecesRootKey = "pieces root"sv;
|
|
|
|
static constexpr std::string_view PrivateKey = "private"sv;
|
|
|
|
static constexpr std::string_view ProfilesKey = "profiles"sv;
|
|
|
|
static constexpr std::string_view PublisherKey = "publisher"sv;
|
2023-03-13 18:58:59 +00:00
|
|
|
static constexpr std::string_view PublisherUtf8Key = "publisher.utf-8"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view PublisherUrlKey = "publisher-url"sv;
|
2023-03-13 18:58:59 +00:00
|
|
|
static constexpr std::string_view PublisherUrlUtf8Key = "publisher-url.utf-8"sv;
|
2022-05-24 20:28:02 +00:00
|
|
|
static constexpr std::string_view Sha1Key = "sha1"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view SourceKey = "source"sv;
|
2022-05-24 20:28:02 +00:00
|
|
|
static constexpr std::string_view TitleKey = "title"sv;
|
2023-04-10 16:07:43 +00:00
|
|
|
static constexpr std::string_view UidKey = "uid"sv;
|
2022-05-24 20:28:02 +00:00
|
|
|
static constexpr std::string_view UniqueKey = "unique"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
static constexpr std::string_view UrlListKey = "url-list"sv;
|
|
|
|
static constexpr std::string_view VcodecKey = "vcodec"sv;
|
|
|
|
static constexpr std::string_view WidthKey = "width"sv;
|
2022-05-24 20:28:02 +00:00
|
|
|
static constexpr std::string_view XCrossSeedKey = "x_cross_seed"sv;
|
2022-05-24 04:05:16 +00:00
|
|
|
};
|
|
|
|
|
2023-11-04 16:39:41 +00:00
|
|
|
bool tr_torrent_metainfo::parse_benc(std::string_view benc, tr_error* error)
|
2022-05-24 04:05:16 +00:00
|
|
|
{
|
|
|
|
auto stack = transmission::benc::ParserStack<MaxBencDepth>{};
|
|
|
|
auto handler = MetainfoHandler{ *this };
|
|
|
|
|
2023-11-04 16:39:41 +00:00
|
|
|
auto local_error = tr_error{};
|
2022-05-24 04:05:16 +00:00
|
|
|
if (error == nullptr)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2023-11-04 16:39:41 +00:00
|
|
|
error = &local_error;
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
2023-11-04 16:39:41 +00:00
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
auto const ok = transmission::benc::parse(benc, stack, handler, nullptr, error);
|
2021-12-25 21:21:13 +00:00
|
|
|
|
2023-11-04 16:39:41 +00:00
|
|
|
if (*error)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2023-11-04 16:39:41 +00:00
|
|
|
tr_logAddError(fmt::format("{} ({})", error->message(), error->code()));
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
if (!ok)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-24 04:05:16 +00:00
|
|
|
if (std::empty(name_))
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
2022-05-24 04:05:16 +00:00
|
|
|
// TODO from first file
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-11-04 16:39:41 +00:00
|
|
|
bool tr_torrent_metainfo::parse_torrent_file(std::string_view filename, std::vector<char>* contents, tr_error* error)
|
2021-12-25 21:21:13 +00:00
|
|
|
{
|
|
|
|
auto local_contents = std::vector<char>{};
|
|
|
|
|
|
|
|
if (contents == nullptr)
|
|
|
|
{
|
|
|
|
contents = &local_contents;
|
|
|
|
}
|
|
|
|
|
2023-06-30 14:49:58 +00:00
|
|
|
return tr_file_read(filename, *contents, error) && parse_benc({ std::data(*contents), std::size(*contents) }, error);
|
2021-12-25 21:21:13 +00:00
|
|
|
}
|
|
|
|
|
2023-08-30 02:58:31 +00:00
|
|
|
std::string tr_torrent_metainfo::make_filename(
|
2022-01-15 19:33:57 +00:00
|
|
|
std::string_view dirname,
|
|
|
|
std::string_view name,
|
|
|
|
std::string_view info_hash_string,
|
|
|
|
BasenameFormat format,
|
|
|
|
std::string_view suffix)
|
|
|
|
{
|
|
|
|
// `${dirname}/${name}.${info_hash}${suffix}`
|
|
|
|
// `${dirname}/${info_hash}${suffix}`
|
2023-08-30 02:58:31 +00:00
|
|
|
auto filename = tr_pathbuf{ dirname, '/' };
|
|
|
|
if (format == BasenameFormat::Hash)
|
|
|
|
{
|
|
|
|
filename.append(info_hash_string);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filename.append(name, '.', info_hash_string.substr(0, 16));
|
|
|
|
}
|
|
|
|
filename.append(suffix);
|
|
|
|
return std::string{ filename.sv() };
|
2022-01-15 19:33:57 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
bool tr_torrent_metainfo::migrate_file(
|
2022-01-15 19:33:57 +00:00
|
|
|
std::string_view dirname,
|
|
|
|
std::string_view name,
|
|
|
|
std::string_view info_hash_string,
|
2022-01-23 22:47:41 +00:00
|
|
|
std::string_view suffix)
|
2022-01-15 19:33:57 +00:00
|
|
|
{
|
2023-04-23 01:25:55 +00:00
|
|
|
auto const old_filename = make_filename(dirname, name, info_hash_string, BasenameFormat::NameAndPartialHash, suffix);
|
2023-03-02 02:12:19 +00:00
|
|
|
if (!tr_sys_path_exists(old_filename))
|
2022-01-15 19:33:57 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
auto const new_filename = make_filename(dirname, name, info_hash_string, BasenameFormat::Hash, suffix);
|
2023-03-02 02:12:19 +00:00
|
|
|
if (tr_sys_path_exists(new_filename))
|
2022-01-15 19:33:57 +00:00
|
|
|
{
|
2023-03-02 02:12:19 +00:00
|
|
|
tr_sys_path_remove(old_filename);
|
2022-01-15 19:33:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-02 02:12:19 +00:00
|
|
|
auto const renamed = tr_sys_path_rename(old_filename, new_filename);
|
|
|
|
if (!renamed)
|
2022-01-17 17:44:53 +00:00
|
|
|
{
|
2022-03-17 22:39:06 +00:00
|
|
|
tr_logAddError(
|
2022-03-14 04:43:35 +00:00
|
|
|
fmt::format(
|
2022-03-16 00:51:36 +00:00
|
|
|
_("Migrated torrent file from '{old_path}' to '{path}'"),
|
|
|
|
fmt::arg("old_path", old_filename),
|
2022-03-17 22:39:06 +00:00
|
|
|
fmt::arg("path", new_filename)),
|
|
|
|
name);
|
2022-01-17 17:44:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-02 02:12:19 +00:00
|
|
|
return renamed;
|
2022-01-15 19:33:57 +00:00
|
|
|
}
|
2022-01-16 18:02:47 +00:00
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
void tr_torrent_metainfo::remove_file(
|
2022-01-18 02:36:41 +00:00
|
|
|
std::string_view dirname,
|
|
|
|
std::string_view name,
|
|
|
|
std::string_view info_hash_string,
|
|
|
|
std::string_view suffix)
|
|
|
|
{
|
2023-04-23 01:25:55 +00:00
|
|
|
auto filename = make_filename(dirname, name, info_hash_string, BasenameFormat::NameAndPartialHash, suffix);
|
2022-05-24 04:05:16 +00:00
|
|
|
tr_sys_path_remove(filename, nullptr);
|
|
|
|
|
2023-04-23 01:25:55 +00:00
|
|
|
filename = make_filename(dirname, name, info_hash_string, BasenameFormat::Hash, suffix);
|
2022-05-24 04:05:16 +00:00
|
|
|
tr_sys_path_remove(filename, nullptr);
|
2022-01-18 02:36:41 +00:00
|
|
|
}
|