forked from premiere/premiere-libtorrent
some windows path fixes
This commit is contained in:
parent
8a4685e83b
commit
af09935b87
20
src/file.cpp
20
src/file.cpp
|
@ -139,6 +139,16 @@ BOOST_STATIC_ASSERT((libtorrent::file::no_buffer & libtorrent::file::attribute_m
|
|||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
std::string convert_separators(std::string p)
|
||||
{
|
||||
for (int i = 0; i < p.size(); ++i)
|
||||
if (p[i] == '/') p[i] = '\\';
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
|
||||
void stat_file(std::string inf, file_status* s
|
||||
, error_code& ec, int flags)
|
||||
{
|
||||
|
@ -641,8 +651,8 @@ namespace libtorrent
|
|||
#ifdef TORRENT_WINDOWS
|
||||
// the path passed to FindFirstFile() must be
|
||||
// a pattern
|
||||
std::string f = path;
|
||||
if (!f.empty() && (f[f.size()-1] != '/' && f[f.size()-1] != '\\')) f += "\\*";
|
||||
std::string f = convert_separators(path);
|
||||
if (!f.empty() && f[f.size()-1] != '\\') f += "\\*";
|
||||
else f += "*";
|
||||
#if TORRENT_USE_WSTRING
|
||||
#define FindFirstFile_ FindFirstFileW
|
||||
|
@ -803,12 +813,12 @@ namespace libtorrent
|
|||
|
||||
#if TORRENT_USE_UNC_PATHS
|
||||
// UNC paths must be absolute
|
||||
std::string p;
|
||||
std::string p = convert_separators(path);
|
||||
// network paths are not supported by UNC paths
|
||||
if (path.substr(0,2) == "\\\\") p = path;
|
||||
else p = "\\\\?\\" + (is_complete(path) ? path : combine_path(current_working_directory(), path));
|
||||
else p = "\\\\?\\" + (is_complete(p) ? p : combine_path(current_working_directory(), p));
|
||||
#else
|
||||
std::string const& p = path;
|
||||
std::string p = convert_separators(path);
|
||||
#endif
|
||||
|
||||
#if TORRENT_USE_WSTRING
|
||||
|
|
|
@ -110,9 +110,9 @@ void test_transfer(bool clear_files, bool disconnect
|
|||
if (tor2.status().is_seeding) std::cerr << "done\n";
|
||||
|
||||
error_code ec;
|
||||
remove_all("./tmp1_meta", ec);
|
||||
remove_all("./tmp2_meta", ec);
|
||||
remove_all("./tmp3_meta", ec);
|
||||
remove_all("tmp1_meta", ec);
|
||||
remove_all("tmp2_meta", ec);
|
||||
remove_all("tmp3_meta", ec);
|
||||
}
|
||||
|
||||
int test_main()
|
||||
|
@ -134,8 +134,8 @@ int test_main()
|
|||
test_transfer(false, false, &create_ut_metadata_plugin);
|
||||
|
||||
error_code ec;
|
||||
remove_all("./tmp1", ec);
|
||||
remove_all("./tmp2", ec);
|
||||
remove_all("tmp1", ec);
|
||||
remove_all("tmp2", ec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -120,9 +120,9 @@ void test_transfer(libtorrent::pe_settings::enc_policy policy,
|
|||
ses2.remove_torrent(tor2);
|
||||
|
||||
error_code ec;
|
||||
remove_all("./tmp1_pe", ec);
|
||||
remove_all("./tmp2_pe", ec);
|
||||
remove_all("./tmp3_pe", ec);
|
||||
remove_all("tmp1_pe", ec);
|
||||
remove_all("tmp2_pe", ec);
|
||||
remove_all("tmp3_pe", ec);
|
||||
}
|
||||
|
||||
void test_enc_handler(libtorrent::encryption_handler* a, libtorrent::encryption_handler* b)
|
||||
|
|
|
@ -154,15 +154,15 @@ int test_main()
|
|||
|
||||
// in case the previous run was terminated
|
||||
error_code ec;
|
||||
remove_all("./tmp1_pex", ec);
|
||||
remove_all("./tmp2_pex", ec);
|
||||
remove_all("./tmp3_pex", ec);
|
||||
remove_all("tmp1_pex", ec);
|
||||
remove_all("tmp2_pex", ec);
|
||||
remove_all("tmp3_pex", ec);
|
||||
|
||||
test_pex();
|
||||
|
||||
remove_all("./tmp1_pex", ec);
|
||||
remove_all("./tmp2_pex", ec);
|
||||
remove_all("./tmp3_pex", ec);
|
||||
remove_all("tmp1_pex", ec);
|
||||
remove_all("tmp2_pex", ec);
|
||||
remove_all("tmp3_pex", ec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -48,9 +48,9 @@ void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode
|
|||
|
||||
// in case the previous run was terminated
|
||||
error_code ec;
|
||||
remove_all("./tmp1_swarm", ec);
|
||||
remove_all("./tmp2_swarm", ec);
|
||||
remove_all("./tmp3_swarm", ec);
|
||||
remove_all("tmp1_swarm", ec);
|
||||
remove_all("tmp2_swarm", ec);
|
||||
remove_all("tmp3_swarm", ec);
|
||||
|
||||
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48000, 49000), "0.0.0.0", 0);
|
||||
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49000, 50000), "0.0.0.0", 0);
|
||||
|
@ -196,13 +196,13 @@ void test_swarm(bool super_seeding = false, bool strict = false, bool seed_mode
|
|||
TEST_CHECK(time_now_hires() - start < seconds(3));
|
||||
TEST_CHECK(time_now_hires() - start >= seconds(2));
|
||||
|
||||
TEST_CHECK(!exists("./tmp1_swarm/temporary"));
|
||||
TEST_CHECK(!exists("./tmp2_swarm/temporary"));
|
||||
TEST_CHECK(!exists("./tmp3_swarm/temporary"));
|
||||
TEST_CHECK(!exists("tmp1_swarm/temporary"));
|
||||
TEST_CHECK(!exists("tmp2_swarm/temporary"));
|
||||
TEST_CHECK(!exists("tmp3_swarm/temporary"));
|
||||
|
||||
remove_all("./tmp1_swarm", ec);
|
||||
remove_all("./tmp2_swarm", ec);
|
||||
remove_all("./tmp3_swarm", ec);
|
||||
remove_all("tmp1_swarm", ec);
|
||||
remove_all("tmp2_swarm", ec);
|
||||
remove_all("tmp3_swarm", ec);
|
||||
}
|
||||
|
||||
int test_main()
|
||||
|
|
|
@ -58,10 +58,10 @@ void test_rate()
|
|||
{
|
||||
// in case the previous run was terminated
|
||||
error_code ec;
|
||||
remove_all("./tmp1_transfer", ec);
|
||||
remove_all("./tmp2_transfer", ec);
|
||||
remove_all("./tmp1_transfer_moved", ec);
|
||||
remove_all("./tmp2_transfer_moved", ec);
|
||||
remove_all("tmp1_transfer", ec);
|
||||
remove_all("tmp2_transfer", ec);
|
||||
remove_all("tmp1_transfer_moved", ec);
|
||||
remove_all("tmp2_transfer_moved", ec);
|
||||
|
||||
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48575, 49000), "0.0.0.0", 0, alert_mask);
|
||||
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49575, 50000), "0.0.0.0", 0, alert_mask);
|
||||
|
@ -69,8 +69,8 @@ void test_rate()
|
|||
torrent_handle tor1;
|
||||
torrent_handle tor2;
|
||||
|
||||
create_directory("./tmp1_transfer", ec);
|
||||
std::ofstream file("./tmp1_transfer/temporary");
|
||||
create_directory("tmp1_transfer", ec);
|
||||
std::ofstream file("tmp1_transfer/temporary");
|
||||
boost::intrusive_ptr<torrent_info> t = ::create_torrent(&file, 4 * 1024 * 1024, 7);
|
||||
file.close();
|
||||
|
||||
|
@ -239,10 +239,10 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
|
|||
|
||||
// in case the previous run was terminated
|
||||
error_code ec;
|
||||
remove_all("./tmp1_transfer", ec);
|
||||
remove_all("./tmp2_transfer", ec);
|
||||
remove_all("./tmp1_transfer_moved", ec);
|
||||
remove_all("./tmp2_transfer_moved", ec);
|
||||
remove_all("tmp1_transfer", ec);
|
||||
remove_all("tmp2_transfer", ec);
|
||||
remove_all("tmp1_transfer_moved", ec);
|
||||
remove_all("tmp2_transfer_moved", ec);
|
||||
|
||||
session ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48075, 49000), "0.0.0.0", 0, alert_mask);
|
||||
session ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49075, 50000), "0.0.0.0", 0, alert_mask);
|
||||
|
@ -308,8 +308,8 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
|
|||
torrent_handle tor1;
|
||||
torrent_handle tor2;
|
||||
|
||||
create_directory("./tmp1_transfer", ec);
|
||||
std::ofstream file("./tmp1_transfer/temporary");
|
||||
create_directory("tmp1_transfer", ec);
|
||||
std::ofstream file("tmp1_transfer/temporary");
|
||||
boost::intrusive_ptr<torrent_info> t = ::create_torrent(&file, 16 * 1024, 13, false);
|
||||
file.close();
|
||||
|
||||
|
@ -388,8 +388,8 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
|
|||
if (!test_move_storage && st2.progress > 0.25f)
|
||||
{
|
||||
test_move_storage = true;
|
||||
tor1.move_storage("./tmp1_transfer_moved");
|
||||
tor2.move_storage("./tmp2_transfer_moved");
|
||||
tor1.move_storage("tmp1_transfer_moved");
|
||||
tor2.move_storage("tmp2_transfer_moved");
|
||||
std::cerr << "moving storage" << std::endl;
|
||||
}
|
||||
|
||||
|
@ -508,7 +508,7 @@ void test_transfer(int proxy_type, bool test_disk_full = false, bool test_allowe
|
|||
p.paused = false;
|
||||
p.auto_managed = false;
|
||||
p.ti = t;
|
||||
p.save_path = "./tmp2_transfer_moved";
|
||||
p.save_path = "tmp2_transfer_moved";
|
||||
p.resume_data = &resume_data;
|
||||
tor2 = ses2.add_torrent(p, ec);
|
||||
ses2.set_alert_mask(alert::all_categories
|
||||
|
@ -607,10 +607,10 @@ int test_main()
|
|||
test_transfer(0, false, true, true);
|
||||
|
||||
error_code ec;
|
||||
remove_all("./tmp1_transfer", ec);
|
||||
remove_all("./tmp2_transfer", ec);
|
||||
remove_all("./tmp1_transfer_moved", ec);
|
||||
remove_all("./tmp2_transfer_moved", ec);
|
||||
remove_all("tmp1_transfer", ec);
|
||||
remove_all("tmp2_transfer", ec);
|
||||
remove_all("tmp1_transfer_moved", ec);
|
||||
remove_all("tmp2_transfer_moved", ec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file
|
|||
ses.listen_on(std::make_pair(51000, 52000), ec);
|
||||
if (ec) fprintf(stderr, "listen_on failed: %s\n", ec.message().c_str());
|
||||
|
||||
remove_all("./tmp2_web_seed", ec);
|
||||
remove_all("tmp2_web_seed", ec);
|
||||
|
||||
char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};
|
||||
|
||||
|
@ -84,7 +84,7 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file
|
|||
p.auto_managed = false;
|
||||
p.paused = false;
|
||||
p.ti = torrent_file;
|
||||
p.save_path = "./tmp2_web_seed";
|
||||
p.save_path = "tmp2_web_seed";
|
||||
p.storage_mode = storage_mode_compact;
|
||||
torrent_handle th = ses.add_torrent(p, ec);
|
||||
|
||||
|
@ -161,9 +161,9 @@ void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file
|
|||
|
||||
if (proxy) stop_proxy(8002);
|
||||
|
||||
TEST_CHECK(exists(combine_path("./tmp2_web_seed", torrent_file->files().file_path(
|
||||
TEST_CHECK(exists(combine_path("tmp2_web_seed", torrent_file->files().file_path(
|
||||
torrent_file->file_at(0)))));
|
||||
remove_all("./tmp2_web_seed", ec);
|
||||
remove_all("tmp2_web_seed", ec);
|
||||
}
|
||||
|
||||
void save_file(char const* filename, char const* data, int size)
|
||||
|
@ -203,7 +203,7 @@ int run_suite(char const* protocol, bool test_url_seed, bool chunked_encoding)
|
|||
using namespace libtorrent;
|
||||
|
||||
error_code ec;
|
||||
create_directories("./tmp1_web_seed/test_torrent_dir", ec);
|
||||
create_directories("tmp1_web_seed/test_torrent_dir", ec);
|
||||
|
||||
file_storage fs;
|
||||
std::srand(10);
|
||||
|
@ -219,11 +219,11 @@ int run_suite(char const* protocol, bool test_url_seed, bool chunked_encoding)
|
|||
{
|
||||
std::generate(random_data, random_data + 300000, &std::rand);
|
||||
char filename[200];
|
||||
snprintf(filename, sizeof(filename), "./tmp1_web_seed/test_torrent_dir/test%d", i);
|
||||
snprintf(filename, sizeof(filename), "tmp1_web_seed/test_torrent_dir/test%d", i);
|
||||
save_file(filename, random_data, file_sizes[i]);
|
||||
}
|
||||
|
||||
add_files(fs, "./tmp1_web_seed/test_torrent_dir");
|
||||
add_files(fs, "tmp1_web_seed/test_torrent_dir");
|
||||
free(random_data);
|
||||
}
|
||||
else
|
||||
|
@ -231,7 +231,7 @@ int run_suite(char const* protocol, bool test_url_seed, bool chunked_encoding)
|
|||
piece_size = 64 * 1024;
|
||||
char* random_data = (char*)malloc(64 * 1024 * 25);
|
||||
std::generate(random_data, random_data + 64 * 1024 * 25, &std::rand);
|
||||
save_file("./tmp1_web_seed/seed", random_data, 64 * 1024 * 25);
|
||||
save_file("tmp1_web_seed/seed", random_data, 64 * 1024 * 25);
|
||||
fs.add_file("seed", 64 * 1024 * 25);
|
||||
free(random_data);
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ int run_suite(char const* protocol, bool test_url_seed, bool chunked_encoding)
|
|||
// for (int i = 0; i < 1000; ++i) sleep(1000);
|
||||
|
||||
// calculate the hash for all pieces
|
||||
set_piece_hashes(t, "./tmp1_web_seed", ec);
|
||||
set_piece_hashes(t, "tmp1_web_seed", ec);
|
||||
|
||||
if (ec)
|
||||
{
|
||||
|
@ -282,7 +282,7 @@ int run_suite(char const* protocol, bool test_url_seed, bool chunked_encoding)
|
|||
for (int i = 0; i < torrent_file->num_files(); ++i)
|
||||
{
|
||||
sha1_hash h1 = torrent_file->file_at(i).filehash;
|
||||
sha1_hash h2 = file_hash(combine_path("./tmp1_web_seed"
|
||||
sha1_hash h2 = file_hash(combine_path("tmp1_web_seed"
|
||||
, torrent_file->file_at(i).path));
|
||||
// fprintf(stderr, "%s: %s == %s\n"
|
||||
// , torrent_file->file_at(i).path.c_str()
|
||||
|
@ -295,12 +295,12 @@ int run_suite(char const* protocol, bool test_url_seed, bool chunked_encoding)
|
|||
|
||||
if (test_url_seed)
|
||||
{
|
||||
torrent_file->rename_file(0, "./tmp2_web_seed/test_torrent_dir/renamed_test1");
|
||||
torrent_file->rename_file(0, "tmp2_web_seed/test_torrent_dir/renamed_test1");
|
||||
test_transfer(torrent_file, 0, port, protocol, test_url_seed, chunked_encoding);
|
||||
}
|
||||
|
||||
stop_web_server();
|
||||
remove_all("./tmp1_web_seed", ec);
|
||||
remove_all("tmp1_web_seed", ec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue