diff --git a/Makefile.am b/Makefile.am index d8cfbea3..f7087db0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,8 +10,6 @@ EXTRA_DIST= \ rak/address_info.h \ rak/algorithm.h \ rak/error_number.h \ - rak/file_stat.h \ - rak/path.h \ rak/partial_queue.h \ rak/regex.h \ rak/string_manip.h \ diff --git a/rak/path.h b/rak/path.h deleted file mode 100644 index d77f1483..00000000 --- a/rak/path.h +++ /dev/null @@ -1,105 +0,0 @@ -// rak - Rakshasa's toolbox -// Copyright (C) 2005-2007, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - -// Various functions for manipulating file paths. Also consider making -// a directory iterator. - -#ifndef RAK_PATH_H -#define RAK_PATH_H - -#include -#include - -namespace rak { - -inline std::string -path_expand(const std::string& path) { - if (path.empty() || path[0] != '~') - return path; - - char* home = std::getenv("HOME"); - - if (home == NULL) - return path; - - return home + path.substr(1); -} - -// Don't inline this... -// -// Same strlcpy as found in *bsd. -inline size_t -strlcpy(char *dest, const char *src, size_t size) { - size_t n = size; - const char* first = src; - - if (n != 0) { - while (--n != 0) - if ((*dest++ = *src++) == '\0') - break; - } - - if (n == 0) { - if (size != 0) - *dest = '\0'; - - while (*src++) - ; - } - - return src - first - 1; -} - -inline char* -path_expand(const char* src, char* first, char* last) { - if (*src == '~') { - char* home = std::getenv("HOME"); - - if (home == NULL) - return first; - - first += strlcpy(first, home, std::distance(first, last)); - - if (first > last) - return last; - - src++; - } - - return std::min(first + strlcpy(first, src, std::distance(first, last)), last); -} - -} - -#endif diff --git a/src/command_download.cc b/src/command_download.cc index 908b25ee..05e3dfdc 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -77,23 +76,23 @@ apply_d_change_link(core::Download* download, const torrent::Object::list_type& if (type == "base_path") { target = rpc::call_command_string("d.base_path", rpc::make_target(download)); - link = rak::path_expand(prefix + rpc::call_command_string("d.base_path", rpc::make_target(download)) + postfix); + link = expand_path(prefix + rpc::call_command_string("d.base_path", rpc::make_target(download)) + postfix); } else if (type == "base_filename") { target = rpc::call_command_string("d.base_path", rpc::make_target(download)); - link = rak::path_expand(prefix + rpc::call_command_string("d.base_filename", rpc::make_target(download)) + postfix); + link = expand_path(prefix + rpc::call_command_string("d.base_filename", rpc::make_target(download)) + postfix); // } else if (type == "directory_path") { // target = rpc::call_command_string("d.directory", rpc::make_target(download)); // link = rak::path_expand(prefix + rpc::call_command_string("d.base_path", rpc::make_target(download)) + postfix); } else if (type == "tied") { - link = rak::path_expand(rpc::call_command_string("d.tied_to_file", rpc::make_target(download))); + link = expand_path(rpc::call_command_string("d.tied_to_file", rpc::make_target(download))); if (link.empty()) return torrent::Object(); - link = rak::path_expand(prefix + link + postfix); + link = expand_path(prefix + link + postfix); target = rpc::call_command_string("d.base_path", rpc::make_target(download)); } else { @@ -131,7 +130,7 @@ apply_d_delete_tied(core::Download* download) { if (tie.empty()) return torrent::Object(); - if (::unlink(rak::path_expand(tie).c_str()) == -1) + if (::unlink(expand_path(tie).c_str()) == -1) control->core()->push_log_std("Could not unlink tied file: " + std::string(std::strerror(errno))); rpc::call_command("d.tied_to_file.set", std::string(), rpc::make_target(download)); diff --git a/src/command_events.cc b/src/command_events.cc index f6e09b69..4c366431 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -69,7 +68,7 @@ apply_start_tied() { torrent::utils::FileStat fs; const std::string& tied_to_file = rpc::call_command_string("d.tied_to_file", rpc::make_target(download)); - if (!tied_to_file.empty() && fs.update(rak::path_expand(tied_to_file))) + if (!tied_to_file.empty() && fs.update(expand_path(tied_to_file))) rpc::parse_command_single(rpc::make_target(download), "d.try_start="); } @@ -85,7 +84,7 @@ apply_stop_untied() { torrent::utils::FileStat fs; const std::string& tied_to_file = rpc::call_command_string("d.tied_to_file", rpc::make_target(download)); - if (!tied_to_file.empty() && !fs.update(rak::path_expand(tied_to_file))) + if (!tied_to_file.empty() && !fs.update(expand_path(tied_to_file))) rpc::parse_command_single(rpc::make_target(download), "d.try_stop="); } @@ -98,7 +97,7 @@ apply_close_untied() { torrent::utils::FileStat fs; const std::string& tied_to_file = rpc::call_command_string("d.tied_to_file", rpc::make_target(download)); - if (rpc::call_command_value("d.ignore_commands", rpc::make_target(download)) == 0 && !tied_to_file.empty() && !fs.update(rak::path_expand(tied_to_file))) + if (rpc::call_command_value("d.ignore_commands", rpc::make_target(download)) == 0 && !tied_to_file.empty() && !fs.update(expand_path(tied_to_file))) rpc::parse_command_single(rpc::make_target(download), "d.try_close="); } @@ -111,7 +110,7 @@ apply_remove_untied() { torrent::utils::FileStat fs; const std::string& tied_to_file = rpc::call_command_string("d.tied_to_file", rpc::make_target(*itr)); - if (!tied_to_file.empty() && !fs.update(rak::path_expand(tied_to_file))) { + if (!tied_to_file.empty() && !fs.update(expand_path(tied_to_file))) { // Need to clear tied_to_file so it doesn't try to delete it. rpc::call_command("d.tied_to_file.set", std::string(), rpc::make_target(*itr)); diff --git a/src/command_file.cc b/src/command_file.cc index ab632ec6..7112d17d 100644 --- a/src/command_file.cc +++ b/src/command_file.cc @@ -1,6 +1,5 @@ #include "config.h" -#include #include #include #include diff --git a/src/command_ip.cc b/src/command_ip.cc index 2ac3bc22..acd2373a 100644 --- a/src/command_ip.cc +++ b/src/command_ip.cc @@ -1,54 +1,18 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #include "config.h" #include -#include -#include -#include -#include - -#include "globals.h" -#include "command_helpers.h" - #include #include #include #include #include #include +#include +#include +#include + +#include "globals.h" +#include "command_helpers.h" bool ipv4_range_parse(const char* address, uint32_t* address_start, uint32_t* address_end); @@ -89,7 +53,7 @@ apply_ip_tables_get(const torrent::Object::list_type& args) { if (table_itr == ip_tables.end()) throw torrent::input_error("Could not find ip table."); - if (!ipv4_range_parse(address.c_str(), &address_start, &address_end)) + if (!ipv4_range_parse(address.c_str(), &address_start, &address_end)) throw torrent::input_error("Invalid address format."); if(!table_itr->table.defined(address_start, address_end)) @@ -298,7 +262,7 @@ apply_ipv4_filter_get(const std::string& args) { uint32_t address_start; uint32_t address_end; - if (!ipv4_range_parse(args.c_str(), &address_start, &address_end)) + if (!ipv4_range_parse(args.c_str(), &address_start, &address_end)) throw torrent::input_error("Invalid address format."); if(!torrent::PeerList::ipv4_filter()->defined(address_start, address_end)) @@ -326,8 +290,8 @@ apply_ipv4_filter_load(const torrent::Object::list_type& args) { std::string value_name = args.back().as_string(); int value = torrent::option_find_string(torrent::OPTION_IP_FILTER, value_name.c_str()); - std::fstream file(rak::path_expand(filename).c_str(), std::ios::in); - + std::fstream file(expand_path(filename).c_str(), std::ios::in); + if (!file.is_open()) throw torrent::input_error("Could not open ip filter file: " + filename); diff --git a/src/command_local.cc b/src/command_local.cc index 01730f7b..3374ae69 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include diff --git a/src/command_logging.cc b/src/command_logging.cc index ecadd1fe..cadc4ac3 100644 --- a/src/command_logging.cc +++ b/src/command_logging.cc @@ -14,7 +14,6 @@ #include "core/download.h" #include "core/download_list.h" #include "core/manager.h" -#include "rak/path.h" #include "rpc/parse_commands.h" static const int log_flag_use_gz = 0x1; @@ -34,8 +33,8 @@ apply_log_open(int output_flags, const torrent::Object::list_type& args) { torrent::Object::list_const_iterator itr = args.begin(); - std::string output_id = (itr++)->as_string(); - std::string file_name = rak::path_expand((itr++)->as_string()); + auto output_id = (itr++)->as_string(); + auto file_name = expand_path((itr++)->as_string()); if ((output_flags & log_flag_append_pid)) { char buffer[32]; @@ -85,7 +84,7 @@ apply_log(const torrent::Object::string_type& arg, int logType) { } if (!arg.empty()) { - int logFd = open(rak::path_expand(arg).c_str(), O_WRONLY | O_APPEND | O_CREAT, 0644); + int logFd = open(expand_path(arg).c_str(), O_WRONLY | O_APPEND | O_CREAT, 0644); if (logFd < 0) throw torrent::input_error("Could not open execute log file."); diff --git a/src/command_network.cc b/src/command_network.cc index 9d68a256..6e2a6460 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -125,7 +124,7 @@ apply_scgi(const std::string& arg, int type) { case 2: default: - path = rak::path_expand(arg); + path = expand_path(arg); unlink(path.c_str()); scgi->open_named(path); diff --git a/src/core/download.cc b/src/core/download.cc index aba75a92..03da3c21 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -3,7 +3,6 @@ #include "core/download.h" #include -#include #include #include #include @@ -19,8 +18,8 @@ namespace core { -Download::Download(download_type d) : - m_download(d) { +Download::Download(download_type d) + : m_download(d) { m_download.info()->signal_tracker_success().push_back(std::bind(&Download::receive_tracker_msg, this, "")); m_download.info()->signal_tracker_failed().push_back(std::bind(&Download::receive_tracker_msg, this, std::placeholders::_1)); @@ -142,7 +141,7 @@ Download::set_root_directory(const std::string& path) { } control->core()->download_list()->close_directly(this); - file_list->set_root_dir(rak::path_expand(path)); + file_list->set_root_dir(expand_path(path)); bencode()->get_key("rtorrent").insert_key("directory", path); } diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index e67065f9..185dda00 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -123,7 +122,7 @@ DownloadFactory::receive_load() { receive_loaded(); } else { - std::fstream stream(rak::path_expand(m_uri).c_str(), std::ios::in | std::ios::binary); + std::fstream stream(expand_path(m_uri).c_str(), std::ios::in | std::ios::binary); if (!stream.is_open()) return receive_failed("Could not open file"); @@ -158,8 +157,8 @@ DownloadFactory::receive_commit() { void DownloadFactory::receive_success() { - auto rtorrent_object = download_factory_load_stream((rak::path_expand(m_uri) + ".rtorrent").c_str()); - auto libtorrent_resume_object = download_factory_load_stream((rak::path_expand(m_uri) + ".libtorrent_resume").c_str()); + auto rtorrent_object = download_factory_load_stream((expand_path(m_uri) + ".rtorrent").c_str()); + auto libtorrent_resume_object = download_factory_load_stream((expand_path(m_uri) + ".libtorrent_resume").c_str()); uint32_t tracker_key; diff --git a/src/core/manager.cc b/src/core/manager.cc index b6f4959f..c9979432 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -1,5 +1,7 @@ #include "config.h" +#include "core/manager.h" + #include #include #include @@ -8,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -33,7 +34,6 @@ #include "core/download.h" #include "core/download_factory.h" #include "core/http_queue.h" -#include "core/manager.h" #include "core/view.h" namespace core { diff --git a/src/input/path_input.cc b/src/input/path_input.cc index 1b21be6a..93baa00c 100644 --- a/src/input/path_input.cc +++ b/src/input/path_input.cc @@ -1,42 +1,7 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #include "config.h" #include #include -#include #include #include @@ -73,7 +38,7 @@ PathInput::receive_do_complete() { size_type dirEnd = find_last_delim(); utils::Directory dir(dirEnd != 0 ? str().substr(0, dirEnd) : "./"); - + if (!dir.update(utils::Directory::update_sort | utils::Directory::update_hide_dot) || dir.empty()) { mark_dirty(); diff --git a/src/rpc/exec_file.cc b/src/rpc/exec_file.cc index edf36697..2faa33f1 100644 --- a/src/rpc/exec_file.cc +++ b/src/rpc/exec_file.cc @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include diff --git a/src/rpc/lua.cc b/src/rpc/lua.cc index 2c4b56f7..a69087c8 100644 --- a/src/rpc/lua.cc +++ b/src/rpc/lua.cc @@ -11,7 +11,6 @@ #include #endif -#include #include #include diff --git a/src/rpc/parse.cc b/src/rpc/parse.cc index 6fe7b66e..ced049bd 100644 --- a/src/rpc/parse.cc +++ b/src/rpc/parse.cc @@ -1,45 +1,11 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #include "config.h" #include #include #include -#include #include +#include "globals.h" #include "parse.h" namespace rpc { @@ -90,7 +56,7 @@ parse_string(const char* first, const char* last, std::string* dest, bool (*deli dest->push_back(*first++); } - + return first; } } @@ -100,7 +66,7 @@ parse_whole_string(const char* first, const char* last, std::string* dest) { first = parse_skip_wspace(first, last); first = parse_string(first, last, dest); first = parse_skip_wspace(first, last); - + if (first != last) throw torrent::input_error("Junk at end of input."); } @@ -175,7 +141,7 @@ parse_object(const char* first, const char* last, torrent::Object* dest, bool (* *dest = torrent::Object::create_list(); first = parse_list(first + 1, last, dest, &parse_is_delim_block); first = parse_skip_wspace(first, last); - + if (first == last || *first != '}') throw torrent::input_error("Could not find closing '}'."); @@ -238,7 +204,7 @@ parse_list(const char* first, const char* last, torrent::Object* dest, bool (*de first = parse_skip_wspace(first, last); dest->as_list().push_back(tmp); - + if (first == last || !parse_is_seperator(*first)) break; @@ -284,12 +250,12 @@ convert_to_string(const torrent::Object& rawSrc) { if (src.as_raw_bencode().is_raw_string()) return src.as_raw_bencode().as_raw_string().as_string(); - + if (src.as_raw_bencode().is_value()) return src.as_raw_bencode().as_value_string(); default: throw torrent::input_error("Not a string."); - } + } } std::string @@ -341,9 +307,9 @@ convert_list_to_command(torrent::Object::list_const_iterator first, if (first == last) throw torrent::input_error("Too few arguments."); - std::string dest = (first++)->as_string(); - std::string::size_type quoteItr = dest.find('='); - + auto dest = (first++)->as_string(); + auto quoteItr = dest.find('='); + if (quoteItr == std::string::npos) throw torrent::input_error("Could not find '=' in command."); @@ -419,7 +385,7 @@ convert_to_value_nothrow(const torrent::Object& src, int64_t* value, int base, i default: return false; } - + return true; } @@ -430,20 +396,23 @@ print_object(char* first, char* last, const torrent::Object* src, int flags) { { const std::string& str = src->as_string(); + if (first == last) + return first; + if ((flags & print_expand_tilde) && *str.c_str() == '~') { - return rak::path_expand(str.c_str(), first, last); + auto expanded = expand_path(str); - } else { - if (first == last) - return first; - - size_t n = std::min(str.size(), std::distance(first, last) - 1); - - std::memcpy(first, str.c_str(), n); + size_t n = std::min(expanded.size(), std::distance(first, last) - 1); + std::memcpy(first, expanded.c_str(), n); *(first += n) = '\0'; - return first; + } else { + size_t n = std::min(str.size(), std::distance(first, last) - 1); + std::memcpy(first, str.c_str(), n); + *(first += n) = '\0'; } + + return first; } case torrent::Object::TYPE_VALUE: @@ -480,7 +449,7 @@ print_object_std(std::string* dest, const torrent::Object* src, int flags) { const std::string& str = src->as_string(); if ((flags & print_expand_tilde) && *str.c_str() == '~') - *dest += rak::path_expand(str); + *dest += expand_path(str); else *dest += str; diff --git a/src/rpc/parse_commands.cc b/src/rpc/parse_commands.cc index a67523d2..964c52a4 100644 --- a/src/rpc/parse_commands.cc +++ b/src/rpc/parse_commands.cc @@ -4,9 +4,9 @@ #include #include #include -#include #include +#include "globals.h" #include "rpc/parse.h" #include "rpc/parse_commands.h" #include "rpc/rpc_manager.h" @@ -140,7 +140,7 @@ parse_command_multiple(target_type target, const char* first, const char* last) bool parse_command_file(const std::string& path) { - std::fstream file(rak::path_expand(path).c_str(), std::ios::in); + std::fstream file(expand_path(path).c_str(), std::ios::in); if (!file.is_open()) return false; diff --git a/src/scgi/thread_scgi.cc b/src/scgi/thread_scgi.cc index edb3aa97..6c33b392 100644 --- a/src/scgi/thread_scgi.cc +++ b/src/scgi/thread_scgi.cc @@ -4,10 +4,10 @@ #include #include -#include #include #include +#include "globals.h" #include "rpc/scgi.h" namespace scgi { @@ -90,7 +90,7 @@ ThreadScgi::change_rpc_log() { if (m_rpc_log_filename.empty()) return; - scgi()->set_log_fd(open(rak::path_expand(m_rpc_log_filename).c_str(), O_WRONLY | O_APPEND | O_CREAT, 0644)); + scgi()->set_log_fd(open(expand_path(m_rpc_log_filename).c_str(), O_WRONLY | O_APPEND | O_CREAT, 0644)); if (scgi()->log_fd() == -1) { lt_log_print(torrent::LOG_NOTICE, "Could not open RPC log file '%s'.", m_rpc_log_filename.c_str()); diff --git a/src/utils/directory.cc b/src/utils/directory.cc index 8f57ee58..77d70448 100644 --- a/src/utils/directory.cc +++ b/src/utils/directory.cc @@ -1,48 +1,14 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell - - #include "config.h" -#include -#include +#include "utils/directory.h" +#include #include +#include #include -#include #include -#include "directory.h" +#include "globals.h" namespace utils { @@ -52,7 +18,7 @@ Directory::is_valid() const { if (m_path.empty()) return false; - DIR* d = opendir(rak::path_expand(m_path).c_str()); + DIR* d = opendir(expand_path(m_path).c_str()); closedir(d); return d; @@ -63,7 +29,7 @@ Directory::update(int flags) { if (m_path.empty()) throw torrent::input_error("Directory::update() tried to open an empty path."); - DIR* d = opendir(rak::path_expand(m_path).c_str()); + DIR* d = opendir(expand_path(m_path).c_str()); if (d == NULL) return false; diff --git a/src/utils/file_status_cache.cc b/src/utils/file_status_cache.cc index 3cbf54d4..a32afef8 100644 --- a/src/utils/file_status_cache.cc +++ b/src/utils/file_status_cache.cc @@ -1,10 +1,11 @@ #include "config.h" -#include +#include "utils/file_status_cache.h" + #include #include -#include "file_status_cache.h" +#include "globals.h" namespace utils { @@ -15,7 +16,7 @@ FileStatusCache::insert(const std::string& path) { // Should we expand somewhere else? Problem is it adds a lot of junk // to the start of the paths added to the cache, causing more work // during search, etc. - if (!fs.update(rak::path_expand(path))) + if (!fs.update(expand_path(path))) return false; std::pair result = base_type::insert(value_type(path, file_status())); @@ -40,7 +41,7 @@ FileStatusCache::prune() { torrent::utils::FileStat fs; iterator tmp = itr++; - if (!fs.update(rak::path_expand(tmp->first)) || tmp->second.m_mtime != (uint32_t)fs.modified_time()) + if (!fs.update(expand_path(tmp->first)) || tmp->second.m_mtime != (uint32_t)fs.modified_time()) base_type::erase(tmp); } } diff --git a/src/utils/file_status_cache.h b/src/utils/file_status_cache.h index 3718d938..f3c795a3 100644 --- a/src/utils/file_status_cache.h +++ b/src/utils/file_status_cache.h @@ -3,6 +3,7 @@ #include #include +#include namespace utils { @@ -31,8 +32,6 @@ public: using base_type::erase; - // static int flag_ - // Insert and return true if the entry does not exist or the new // file's mtime is more recent. bool insert(const std::string& path);