make flags to move_storage a proper enum class (#2043)

This commit is contained in:
Arvid Norberg 2017-06-01 04:15:15 -04:00 committed by GitHub
parent c5cdd381da
commit 5344761da4
16 changed files with 69 additions and 41 deletions

View File

@ -441,11 +441,11 @@ void bind_torrent_handle()
int (torrent_handle::*piece_priority0)(piece_index_t) const = &torrent_handle::piece_priority;
void (torrent_handle::*piece_priority1)(piece_index_t, int) const = &torrent_handle::piece_priority;
void (torrent_handle::*move_storage0)(std::string const&, int flags) const = &torrent_handle::move_storage;
void (torrent_handle::*move_storage0)(std::string const&, lt::move_flags_t) const = &torrent_handle::move_storage;
void (torrent_handle::*rename_file0)(file_index_t, std::string const&) const = &torrent_handle::rename_file;
#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE
void (torrent_handle::*move_storage1)(std::wstring const&, int flags) const = &torrent_handle::move_storage;
void (torrent_handle::*move_storage1)(std::wstring const&, int) const = &torrent_handle::move_storage;
void (torrent_handle::*rename_file1)(file_index_t, std::wstring const&) const = &torrent_handle::rename_file;
#endif
@ -453,6 +453,12 @@ void bind_torrent_handle()
#define _ allow_threads
enum_<move_flags_t>("move_flags_t")
.value("always_replace_files", move_flags_t::always_replace_files)
.value("fail_if_exist", move_flags_t::fail_if_exist)
.value("dont_replace", move_flags_t::dont_replace)
;
class_<torrent_handle>("torrent_handle")
.def(self == self)
.def(self != self)
@ -548,13 +554,13 @@ void bind_torrent_handle()
#ifndef TORRENT_NO_DEPRECATE
.def("set_tracker_login", &torrent_handle::set_tracker_login)
#endif
.def("move_storage", _(move_storage0), (arg("path"), arg("flags") = 0))
.def("move_storage", _(move_storage0), (arg("path"), arg("flags") = move_flags_t::always_replace_files))
.def("info_hash", _(&torrent_handle::info_hash))
.def("force_recheck", _(&torrent_handle::force_recheck))
.def("rename_file", _(rename_file0))
.def("set_ssl_certificate", &torrent_handle::set_ssl_certificate, (arg("cert"), arg("private_key"), arg("dh_params"), arg("passphrase")=""))
#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE
.def("move_storage", _(move_storage1), (arg("path"), arg("flags") = 0))
.def("move_storage", _(move_storage1), (arg("path"), arg("flags") = always_replace_files))
.def("rename_file", _(rename_file1))
#endif
;
@ -605,11 +611,6 @@ void bind_torrent_handle()
.value("query_verified_pieces", torrent_handle::query_verified_pieces)
;
enum_<move_flags_t>("move_flags_t")
.value("always_replace_files", always_replace_files)
.value("fail_if_exist", fail_if_exist)
.value("dont_replace", dont_replace)
;
}
#ifdef _MSC_VER

View File

@ -77,7 +77,7 @@ namespace libtorrent {
, std::string const& save_path
, std::string const& destination_save_path
, part_file* pf
, int const flags, storage_error& ec);
, move_flags_t flags, storage_error& ec);
// deletes the files on fs from save_path according to options. Options may
// opt to only delete the partfile

View File

@ -145,7 +145,7 @@ namespace libtorrent {
, std::uint8_t flags = 0) = 0;
virtual void async_hash(storage_index_t storage, piece_index_t piece, std::uint8_t flags
, std::function<void(piece_index_t, sha1_hash const&, storage_error const&)> handler, void* requester) = 0;
virtual void async_move_storage(storage_index_t storage, std::string p, std::uint8_t flags
virtual void async_move_storage(storage_index_t storage, std::string p, move_flags_t flags
, std::function<void(status_t, std::string const&, storage_error const&)> handler) = 0;
virtual void async_release_files(storage_index_t storage
, std::function<void()> handler = std::function<void()>()) = 0;

View File

@ -204,6 +204,8 @@ namespace libtorrent {
// flags controlling this job
std::uint8_t flags = 0;
move_flags_t move_flags = move_flags_t::always_replace_files;
#if TORRENT_USE_ASSERTS
bool in_use = false;

View File

@ -306,7 +306,7 @@ namespace aux {
, std::uint8_t flags = 0) override;
void async_hash(storage_index_t storage, piece_index_t piece, std::uint8_t flags
, std::function<void(piece_index_t, sha1_hash const&, storage_error const&)> handler, void* requester) override;
void async_move_storage(storage_index_t storage, std::string p, std::uint8_t flags
void async_move_storage(storage_index_t storage, std::string p, move_flags_t flags
, std::function<void(status_t, std::string const&, storage_error const&)> handler) override;
void async_release_files(storage_index_t storage
, std::function<void()> handler = std::function<void()>()) override;

View File

@ -234,8 +234,8 @@ namespace libtorrent {
// like ``release_files()``.
//
//If an error occurs, ``storage_error`` should be set to reflect it.
virtual status_t move_storage(std::string const& save_path, int flags
, storage_error& ec) = 0;
virtual status_t move_storage(std::string const& save_path
, move_flags_t flags, storage_error& ec) = 0;
// This function should verify the resume data ``rd`` with the files
// on disk. If the resume data seems to be up-to-date, return true. If
@ -390,8 +390,8 @@ namespace libtorrent {
virtual void release_files(storage_error& ec) override;
virtual void delete_files(int options, storage_error& ec) override;
virtual void initialize(storage_error& ec) override;
virtual status_t move_storage(std::string const& save_path, int flags
, storage_error& ec) override;
virtual status_t move_storage(std::string const& save_path
, move_flags_t flags, storage_error& ec) override;
virtual bool verify_resume_data(add_torrent_params const& rd
, aux::vector<std::string, file_index_t> const& links
, storage_error& error) override;

View File

@ -72,7 +72,7 @@ namespace libtorrent {
};
// flags for async_move_storage
enum move_flags_t
enum class move_flags_t : std::uint8_t
{
// replace any files in the destination when copying
// or moving the storage
@ -92,6 +92,16 @@ namespace libtorrent {
dont_replace
};
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
enum deprecated_move_flags_t
{
always_replace_files TORRENT_DEPRECATED_ENUM,
fail_if_exist TORRENT_DEPRECATED_ENUM,
dont_replace TORRENT_DEPRECATED_ENUM
};
#endif
struct TORRENT_EXPORT storage_params
{
file_storage const* files = nullptr;

View File

@ -1014,7 +1014,7 @@ namespace libtorrent {
// RESOURCE MANAGEMENT
// flags are defined in storage.hpp
void move_storage(std::string const& save_path, int flags);
void move_storage(std::string const& save_path, move_flags_t flags);
// renames the file with the given index to the new name
// the name may include a directory path

View File

@ -53,6 +53,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/units.hpp"
#include "libtorrent/aux_/vector.hpp"
#include "libtorrent/storage_defs.hpp"
namespace libtorrent { namespace aux {
@ -1211,10 +1212,6 @@ namespace libtorrent { namespace aux {
// The ``flags`` argument determines the behavior of the copying/moving
// of the files in the torrent. see move_flags_t.
//
// * always_replace_files = 0
// * fail_if_exist = 1
// * dont_replace = 2
//
// ``always_replace_files`` is the default and replaces any file that
// exist in both the source directory and the target directory.
//
@ -1241,7 +1238,18 @@ namespace libtorrent { namespace aux {
// torrent but are stored in the torrent's directory may be moved as
// well. This goes for files that have been renamed to absolute paths
// that still end up inside the save path.
void move_storage(std::string const& save_path
, move_flags_t flags
#ifdef TORRENT_NO_DEPRECATE
= move_flags_t::always_replace_files
#endif
) const;
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
TORRENT_DEPRECATED
void move_storage(std::string const& save_path, int flags = 0) const;
#endif
// Renames the file with the given index asynchronously. The rename
// operation is complete when either a file_renamed_alert or

View File

@ -1805,14 +1805,14 @@ namespace libtorrent {
}
void disk_io_thread::async_move_storage(storage_index_t const storage
, std::string p, std::uint8_t const flags
, std::string p, move_flags_t const flags
, std::function<void(status_t, std::string const&, storage_error const&)> handler)
{
disk_io_job* j = allocate_job(disk_io_job::move_storage);
j->storage = m_torrents[storage]->shared_from_this();
j->argument = std::move(p);
j->callback = std::move(handler);
j->flags = flags;
j->move_flags = flags;
add_fence_job(j);
}
@ -2447,7 +2447,7 @@ namespace libtorrent {
// if files have to be closed, that's the storage's responsibility
return j->storage->move_storage(boost::get<std::string>(j->argument)
, j->flags, j->error);
, j->move_flags, j->error);
}
status_t disk_io_thread::do_release_files(disk_io_job* j, jobqueue_t& completed_jobs)

View File

@ -450,8 +450,8 @@ namespace libtorrent {
, m_file_priority, m_stat_cache, m_save_path, ec);
}
status_t default_storage::move_storage(std::string const& sp, int const flags
, storage_error& ec)
status_t default_storage::move_storage(std::string const& sp
, move_flags_t const flags, storage_error& ec)
{
m_pool.release(storage_index());
@ -737,7 +737,7 @@ namespace {
void release_files(storage_error&) override {}
void delete_files(int, storage_error&) override {}
void initialize(storage_error&) override {}
status_t move_storage(std::string const&, int, storage_error&) override { return status_t::no_error; }
status_t move_storage(std::string const&, move_flags_t, storage_error&) override { return status_t::no_error; }
int readv(span<iovec_t const> bufs
, piece_index_t, int, open_mode_t, storage_error&) override
@ -796,7 +796,7 @@ namespace {
void set_file_priority(aux::vector<std::uint8_t, file_index_t> const& /* prio */
, storage_error&) override {}
status_t move_storage(std::string const& /* save_path */
, int /* flags */, storage_error&) override { return status_t::no_error; }
, move_flags_t, storage_error&) override { return status_t::no_error; }
bool verify_resume_data(add_torrent_params const& /* rd */
, aux::vector<std::string, file_index_t> const& /* links */
, storage_error&) override

View File

@ -199,13 +199,13 @@ namespace libtorrent { namespace aux {
, std::string const& save_path
, std::string const& destination_save_path
, part_file* pf
, int const flags, storage_error& ec)
, move_flags_t const flags, storage_error& ec)
{
status_t ret = status_t::no_error;
std::string const new_save_path = complete(destination_save_path);
// check to see if any of the files exist
if (flags == fail_if_exist)
if (flags == move_flags_t::fail_if_exist)
{
file_status s;
error_code err;
@ -269,7 +269,7 @@ namespace libtorrent { namespace aux {
std::string const old_path = combine_path(save_path, f.file_path(i));
std::string const new_path = combine_path(new_save_path, f.file_path(i));
if (flags == dont_replace && exists(new_path))
if (flags == move_flags_t::dont_replace && exists(new_path))
{
if (ret == status_t::no_error) ret = status_t::need_full_check;
continue;

View File

@ -7520,7 +7520,7 @@ namespace libtorrent {
return;
}
void torrent::move_storage(std::string const& save_path, int const flags)
void torrent::move_storage(std::string const& save_path, move_flags_t const flags)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
@ -7551,7 +7551,7 @@ namespace libtorrent {
#else
std::string path = save_path;
#endif
m_ses.disk_thread().async_move_storage(m_storage, std::move(path), std::uint8_t(flags)
m_ses.disk_thread().async_move_storage(m_storage, std::move(path), flags
, std::bind(&torrent::on_storage_moved, shared_from_this(), _1, _2, _3));
m_moving_storage = true;
}

View File

@ -212,18 +212,25 @@ namespace libtorrent {
return sync_call_ret<int>(0, &torrent::download_limit);
}
void torrent_handle::move_storage(
std::string const& save_path, int flags) const
void torrent_handle::move_storage(std::string const& save_path, move_flags_t flags) const
{
async_call(&torrent::move_storage, save_path, flags);
}
#ifndef TORRENT_NO_DEPRECATE
void torrent_handle::move_storage(
std::string const& save_path, int const flags) const
{
async_call(&torrent::move_storage, save_path, static_cast<move_flags_t>(flags));
}
#endif
#if TORRENT_USE_WSTRING
#ifndef TORRENT_NO_DEPRECATE
void torrent_handle::move_storage(
std::wstring const& save_path, int flags) const
{
async_call(&torrent::move_storage, wchar_utf8(save_path), flags);
async_call(&torrent::move_storage, wchar_utf8(save_path), static_cast<move_flags_t>(flags));
}
void torrent_handle::rename_file(file_index_t index, std::wstring const& new_name) const

View File

@ -64,7 +64,7 @@ struct test_storage_impl : storage_interface
bool has_any_file(storage_error& ec) override { return false; }
void set_file_priority(aux::vector<std::uint8_t, file_index_t> const& prio
, storage_error& ec) override {}
status_t move_storage(std::string const& save_path, int flags
status_t move_storage(std::string const& save_path, move_flags_t flags
, storage_error& ec) override { return status_t::no_error; }
bool verify_resume_data(add_torrent_params const& rd
, aux::vector<std::string, file_index_t> const& links

View File

@ -1367,7 +1367,7 @@ TORRENT_TEST(move_storage_to_self)
TEST_CHECK(exists(combine_path(test_path, combine_path("folder2", "test3.tmp"))));
TEST_CHECK(exists(combine_path(test_path, combine_path("_folder3", "test4.tmp"))));
s->move_storage(save_path, 0, se);
s->move_storage(save_path, move_flags_t::always_replace_files, se);
TEST_EQUAL(se.ec, boost::system::errc::success);
TEST_CHECK(exists(test_path));
@ -1394,7 +1394,7 @@ TORRENT_TEST(move_storage_into_self)
s->writev(b, piece_index_t(2), 0, open_mode_t::read_write, se);
std::string const test_path = combine_path(save_path, combine_path("temp_storage", "folder1"));
s->move_storage(test_path, 0, se);
s->move_storage(test_path, move_flags_t::always_replace_files, se);
TEST_EQUAL(se.ec, boost::system::errc::success);
TEST_CHECK(exists(combine_path(test_path, combine_path("temp_storage"
@ -1453,7 +1453,7 @@ TORRENT_TEST(dont_move_intermingled_files)
f.close();
TEST_EQUAL(ec, boost::system::errc::success);
s->move_storage(test_path, 0, se);
s->move_storage(test_path, move_flags_t::always_replace_files, se);
TEST_EQUAL(se.ec, boost::system::errc::success);
// torrent files moved to new place