Skip to content

Commit 7ab44d4

Browse files
committed
make the save path for part files configurable
1 parent 8136bec commit 7ab44d4

22 files changed

+267
-26
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2.1.0 not released
22

3+
* make the save path for part files configurable
34
* retry failed SAM connection (for i2p)
45
* deprecated remap_files(), and prevent it from breaking v2 torrents
56
* fix peer_info holding an i2p destination

bindings/python/src/session.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ namespace
339339
p.save_path = extract<std::string>(value);
340340
continue;
341341
}
342+
else if(key == "part_file_dir")
343+
{
344+
p.part_file_dir = extract<std::string>(value);
345+
continue;
346+
}
342347
#if TORRENT_ABI_VERSION == 1
343348
else if(key == "resume_data")
344349
{
@@ -1006,6 +1011,7 @@ void bind_session()
10061011
.add_property("dht_nodes", PROP(&add_torrent_params::dht_nodes))
10071012
.def_readwrite("name", &add_torrent_params::name)
10081013
.def_readwrite("save_path", &add_torrent_params::save_path)
1014+
.def_readwrite("part_file_dir", &add_torrent_params::part_file_dir)
10091015
.def_readwrite("storage_mode", &add_torrent_params::storage_mode)
10101016
// .def_readwrite("storage", &add_torrent_params::storage)
10111017
.add_property("file_priorities", PROP(&add_torrent_params::file_priorities))

examples/connection_tester.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ void generate_data(std::string const path, torrent_info const& ti)
939939
fs,
940940
rf,
941941
path,
942+
{},
942943
storage_mode_sparse,
943944
priorities,
944945
info_hash,

include/libtorrent/add_torrent_params.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ TORRENT_VERSION_NAMESPACE_3
145145
// The name out of the torrent_info object takes precedence if available.
146146
std::string name;
147147

148-
// the path where the torrent is or will be stored.
148+
// The path to the directory where the torrent is or will be stored.
149149
//
150150
// .. note::
151151
// On windows this path (and other paths) are interpreted as UNC
@@ -156,6 +156,17 @@ TORRENT_VERSION_NAMESPACE_3
156156
// relative path.
157157
std::string save_path;
158158

159+
// This is an optional field. If set, the part-file for this torrent
160+
// will be stored in the specified subdirectory, still inside its
161+
// download directory. The part file name is the info-hash, in hexadecimal
162+
// form. By default it's stored directly in the download directory.
163+
// If the storage for a torrent is moved, the part file is also moved
164+
// along with it, to the new download directory.
165+
// A part file contains partial pieces that
166+
// need to be downloaded in order to verify hashes and seeding, but are
167+
// part of files whose priority is zero.
168+
std::string part_file_dir;
169+
159170
// One of the values from storage_mode_t. For more information, see
160171
// storage-allocation_.
161172
storage_mode_t storage_mode = storage_mode_sparse;

include/libtorrent/aux_/mmap_storage.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ namespace libtorrent::aux {
153153

154154
aux::vector<download_priority_t, file_index_t> m_file_priority;
155155
std::string m_save_path;
156+
std::string m_part_file_dir;
156157
std::string m_part_file_name;
157158

158159
// this this is an array indexed by file-index. Each slot represents

include/libtorrent/aux_/posix_storage.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ namespace aux {
7676
file_storage const& m_files;
7777
renamed_files m_renamed_files;
7878
std::string m_save_path;
79+
std::string m_part_file_dir;
7980
stat_cache m_stat_cache;
8081

8182
aux::vector<download_priority_t, file_index_t> m_file_priority;

include/libtorrent/aux_/storage_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace libtorrent::aux {
4141
// opt to only delete the partfile
4242
TORRENT_EXTRA_EXPORT void
4343
delete_files(filenames const& fs, std::string const& save_path
44-
, std::string const& part_file_name, remove_flags_t options, storage_error& ec);
44+
, std::string const& part_file, remove_flags_t options, storage_error& ec);
4545

4646
TORRENT_EXTRA_EXPORT bool
4747
verify_resume_data(add_torrent_params const& rd

include/libtorrent/aux_/torrent.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,7 @@ namespace libtorrent::aux {
14011401
#endif
14021402

14031403
std::string m_save_path;
1404+
std::string m_part_file_dir;
14041405
aux::cached_slot m_name_idx;
14051406

14061407
#ifndef TORRENT_DISABLE_PREDICTIVE_PIECES

include/libtorrent/storage_defs.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ see LICENSE file.
1818
#include "libtorrent/aux_/vector.hpp"
1919
#include "libtorrent/sha1_hash.hpp"
2020
#include "libtorrent/download_priority.hpp"
21+
#include "libtorrent/string_view.hpp"
2122
#include <functional>
2223
#include <string>
2324

@@ -82,12 +83,13 @@ namespace libtorrent {
8283
struct TORRENT_EXPORT storage_params
8384
{
8485
storage_params(file_storage const& f, lt::renamed_files const& mf
85-
, std::string const& sp, storage_mode_t const sm
86+
, string_view sp, string_view pfd, storage_mode_t const sm
8687
, aux::vector<download_priority_t, file_index_t> const& prio
8788
, sha1_hash const& ih, bool v1_torrent, bool v2_torrent)
8889
: files(f)
8990
, renamed_files(mf)
9091
, path(sp)
92+
, part_file_dir(pfd)
9193
, mode(sm)
9294
, priorities(prio)
9395
, info_hash(ih)
@@ -96,7 +98,8 @@ namespace libtorrent {
9698
{}
9799
file_storage const& files;
98100
lt::renamed_files const& renamed_files;
99-
std::string const& path;
101+
string_view path;
102+
string_view part_file_dir;
100103
storage_mode_t mode{storage_mode_sparse};
101104
aux::vector<download_priority_t, file_index_t> const& priorities;
102105
sha1_hash info_hash;

src/create_torrent.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ namespace {
483483
fs,
484484
rf,
485485
path,
486+
{},
486487
storage_mode_t::storage_mode_sparse,
487488
priorities,
488489
sha1_hash{},

0 commit comments

Comments
 (0)