optimize client_test path handling (#1845)
optimize client_test path handling
This commit is contained in:
parent
8cc17a4524
commit
2c131dbbc4
|
@ -623,8 +623,31 @@ void add_torrent(libtorrent::session& ses
|
||||||
files.insert(std::pair<const std::string, torrent_handle>(torrent, torrent_handle()));
|
files.insert(std::pair<const std::string, torrent_handle>(torrent, torrent_handle()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string make_absolute_path(char const* p)
|
||||||
|
{
|
||||||
|
std::string ret;
|
||||||
|
#if defined TORRENT_WINDOWS
|
||||||
|
if (p[0] != '\0' && !(p[1] == ':' && p[2] == '\\'))
|
||||||
|
{
|
||||||
|
char* cwd = ::_getcwd(nullptr, 0);
|
||||||
|
ret = path_append(cwd, p);
|
||||||
|
std::free(cwd);
|
||||||
|
}
|
||||||
|
else ret = p;
|
||||||
|
#else
|
||||||
|
if (p[0] != '/')
|
||||||
|
{
|
||||||
|
char* cwd = ::getcwd(nullptr, 0);
|
||||||
|
ret = path_append(cwd, p);
|
||||||
|
std::free(cwd);
|
||||||
|
}
|
||||||
|
else ret = p;
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> list_dir(std::string path
|
std::vector<std::string> list_dir(std::string path
|
||||||
, bool (*filter_fun)(std::string const&)
|
, bool (*filter_fun)(lt::string_view)
|
||||||
, libtorrent::error_code& ec)
|
, libtorrent::error_code& ec)
|
||||||
{
|
{
|
||||||
std::vector<std::string> ret;
|
std::vector<std::string> ret;
|
||||||
|
@ -642,9 +665,9 @@ std::vector<std::string> list_dir(std::string path
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::string p = fd.cFileName;
|
lt::string_view p = fd.cFileName;
|
||||||
if (filter_fun(p))
|
if (filter_fun(p))
|
||||||
ret.push_back(p);
|
ret.push_back(p.to_string());
|
||||||
|
|
||||||
} while (FindNextFileA(handle, &fd));
|
} while (FindNextFileA(handle, &fd));
|
||||||
FindClose(handle);
|
FindClose(handle);
|
||||||
|
@ -666,32 +689,21 @@ std::vector<std::string> list_dir(std::string path
|
||||||
{
|
{
|
||||||
if (dummy == nullptr) break;
|
if (dummy == nullptr) break;
|
||||||
|
|
||||||
std::string p = de.d_name;
|
lt::string_view p(de.d_name);
|
||||||
if (filter_fun(p))
|
if (filter_fun(p))
|
||||||
ret.push_back(p);
|
ret.push_back(p.to_string());
|
||||||
}
|
}
|
||||||
closedir(handle);
|
closedir(handle);
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool filter_fun(std::string const& p)
|
bool filter_fun(lt::string_view p)
|
||||||
{
|
{
|
||||||
for (int i = int(p.size()) - 1; i >= 0; --i)
|
return p.size() > 8 && p.substr(p.size() - 8) == ".torrent";
|
||||||
{
|
|
||||||
if (p[i] == '/') break;
|
|
||||||
#ifdef TORRENT_WINDOWS
|
|
||||||
if (p[i] == '\\') break;
|
|
||||||
#endif
|
|
||||||
if (p[i] != '.') continue;
|
|
||||||
return p.compare(i, 8, ".torrent") == 0;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void scan_dir(std::string const& dir_path
|
void scan_dir(std::string const& dir_path, libtorrent::session& ses, handles_t& files)
|
||||||
, libtorrent::session& ses
|
|
||||||
, handles_t& files)
|
|
||||||
{
|
{
|
||||||
std::set<std::string> valid;
|
std::set<std::string> valid;
|
||||||
|
|
||||||
|
@ -706,10 +718,9 @@ void scan_dir(std::string const& dir_path
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::vector<std::string>::iterator i = ents.begin()
|
for (auto const& e : ents)
|
||||||
, end(ents.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
std::string file = path_append(dir_path, *i);
|
std::string const file = path_append(dir_path, e);
|
||||||
|
|
||||||
handles_t::iterator k = files.find(file);
|
handles_t::iterator k = files.find(file);
|
||||||
if (k != files.end())
|
if (k != files.end())
|
||||||
|
@ -1253,10 +1264,10 @@ int main(int argc, char* argv[])
|
||||||
case 'f': g_log_file = std::fopen(arg, "w+"); break;
|
case 'f': g_log_file = std::fopen(arg, "w+"); break;
|
||||||
case 'k': settings = high_performance_seed(); --i; break;
|
case 'k': settings = high_performance_seed(); --i; break;
|
||||||
case 'G': seed_mode = true; --i; break;
|
case 'G': seed_mode = true; --i; break;
|
||||||
case 's': save_path = arg; break;
|
case 's': save_path = make_absolute_path(arg); break;
|
||||||
case 'U': torrent_upload_limit = atoi(arg) * 1000; break;
|
case 'U': torrent_upload_limit = atoi(arg) * 1000; break;
|
||||||
case 'D': torrent_download_limit = atoi(arg) * 1000; break;
|
case 'D': torrent_download_limit = atoi(arg) * 1000; break;
|
||||||
case 'm': monitor_dir = arg; break;
|
case 'm': monitor_dir = make_absolute_path(arg); break;
|
||||||
case 'Q': share_mode = true; --i; break;
|
case 'Q': share_mode = true; --i; break;
|
||||||
case 't': poll_interval = atoi(arg); break;
|
case 't': poll_interval = atoi(arg); break;
|
||||||
case 'F': refresh_delay = atoi(arg); break;
|
case 'F': refresh_delay = atoi(arg); break;
|
||||||
|
|
Loading…
Reference in New Issue