diff --git a/rak/error_number.h b/rak/error_number.h deleted file mode 100644 index 7cea7852..00000000 --- a/rak/error_number.h +++ /dev/null @@ -1,85 +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 - -#ifndef RAK_ERROR_NUMBER_H -#define RAK_ERROR_NUMBER_H - -#include -#include - -namespace rak { - -class error_number { -public: - static const int e_access = EACCES; - static const int e_again = EAGAIN; - static const int e_connreset = ECONNRESET; - static const int e_connaborted = ECONNABORTED; - static const int e_deadlk = EDEADLK; - - static const int e_noent = ENOENT; - static const int e_nodev = ENODEV; - static const int e_nomem = ENOMEM; - static const int e_notdir = ENOTDIR; - static const int e_isdir = EISDIR; - - static const int e_intr = EINTR; - - error_number() : m_errno(0) {} - error_number(int e) : m_errno(e) {} - - bool is_valid() const { return m_errno != 0; } - - int value() const { return m_errno; } - const char* c_str() const { return std::strerror(m_errno); } - - bool is_blocked_momentary() const { return m_errno == e_again || m_errno == e_intr; } - bool is_blocked_prolonged() const { return m_errno == e_deadlk; } - - bool is_closed() const { return m_errno == e_connreset || m_errno == e_connaborted; } - - bool is_bad_path() const { return m_errno == e_noent || m_errno == e_notdir || m_errno == e_access; } - - static error_number current() { return errno; } - static void clear_global() { errno = 0; } - static void set_global(error_number err) { errno = err.m_errno; } - - bool operator == (const error_number& e) const { return m_errno == e.m_errno; } - -private: - int m_errno; -}; - -} - -#endif diff --git a/rak/file_stat.h b/rak/file_stat.h deleted file mode 100644 index a0c27443..00000000 --- a/rak/file_stat.h +++ /dev/null @@ -1,75 +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 - - -#ifndef RAK_FILE_STAT_H -#define RAK_FILE_STAT_H - -#include -#include -#include - -namespace rak { - -class file_stat { -public: - // Consider storing rak::error_number. - - bool update(int fd) { return fstat(fd, &m_stat) == 0; } - bool update(const char* filename) { return stat(filename, &m_stat) == 0; } - bool update(const std::string& filename) { return update(filename.c_str()); } - - bool update_link(const char* filename) { return lstat(filename, &m_stat) == 0; } - bool update_link(const std::string& filename) { return update_link(filename.c_str()); } - - bool is_regular() const { return S_ISREG(m_stat.st_mode); } - bool is_directory() const { return S_ISDIR(m_stat.st_mode); } - bool is_character() const { return S_ISCHR(m_stat.st_mode); } - bool is_block() const { return S_ISBLK(m_stat.st_mode); } - bool is_fifo() const { return S_ISFIFO(m_stat.st_mode); } - bool is_link() const { return S_ISLNK(m_stat.st_mode); } - bool is_socket() const { return S_ISSOCK(m_stat.st_mode); } - - off_t size() const { return m_stat.st_size; } - - time_t access_time() const { return m_stat.st_atime; } - time_t change_time() const { return m_stat.st_ctime; } - time_t modified_time() const { return m_stat.st_mtime; } - -private: - struct stat m_stat; -}; - -} - -#endif diff --git a/src/command_download.cc b/src/command_download.cc index c6b319a8..908b25ee 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include #include #include @@ -109,7 +109,7 @@ apply_d_change_link(core::Download* download, const torrent::Object::list_type& case 1: { - rak::file_stat fileStat; + torrent::utils::FileStat fileStat; errno = 0; if (!fileStat.update_link(link) || !fileStat.is_link() || unlink(link.c_str()) == -1) diff --git a/src/command_events.cc b/src/command_events.cc index ae2f01dd..f6e09b69 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -2,14 +2,13 @@ #include #include -#include -#include #include #include #include #include #include #include +#include #include "globals.h" #include "control.h" @@ -67,7 +66,7 @@ apply_start_tied() { if (rpc::call_command_value("d.state", rpc::make_target(download)) == 1) continue; - rak::file_stat fs; + 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))) @@ -83,7 +82,7 @@ apply_stop_untied() { if (rpc::call_command_value("d.state", rpc::make_target(download)) == 0) continue; - rak::file_stat fs; + 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))) @@ -96,7 +95,7 @@ apply_stop_untied() { torrent::Object apply_close_untied() { for (const auto& download : *control->core()->download_list()) { - rak::file_stat fs; + 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))) @@ -109,7 +108,7 @@ apply_close_untied() { torrent::Object apply_remove_untied() { for (auto itr = control->core()->download_list()->begin(); itr != control->core()->download_list()->end(); ) { - rak::file_stat fs; + 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))) { @@ -301,7 +300,7 @@ directory_watch_added(const torrent::Object::list_type& args) { auto& command = args.back().as_string(); if (!control->directory_events()->open()) - throw torrent::input_error("Could not open inotify:" + std::string(rak::error_number::current().c_str())); + throw torrent::input_error("Could not open inotify:" + std::string(std::strerror(errno))); control->directory_events()->notify_on(path.c_str(), torrent::directory_events::flag_on_added | torrent::directory_events::flag_on_updated, diff --git a/src/command_file.cc b/src/command_file.cc index 373c8216..ab632ec6 100644 --- a/src/command_file.cc +++ b/src/command_file.cc @@ -1,40 +1,5 @@ -// 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 diff --git a/src/command_local.cc b/src/command_local.cc index b6ea0329..01730f7b 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -1,11 +1,11 @@ #include "config.h" +#include #include #include #include #include #include -#include #include #include #include @@ -171,8 +171,8 @@ cmd_file_append(const torrent::Object::list_type& args) { FILE* output = fopen(args.front().as_string().c_str(), "a"); - if (output == NULL) - throw torrent::input_error("Could not append to file '" + args.front().as_string() + "': " + rak::error_number::current().c_str()); + if (output == nullptr) + throw torrent::input_error("Could not append to file '" + args.front().as_string() + "': " + std::strerror(errno)); file_print_list(++args.begin(), args.end(), output, file_print_delim_space); diff --git a/src/core/download.cc b/src/core/download.cc index dee49922..aba75a92 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -1,7 +1,8 @@ #include "config.h" +#include "core/download.h" + #include -#include #include #include #include @@ -9,12 +10,12 @@ #include #include #include +#include #include "rpc/parse_commands.h" #include "control.h" -#include "download.h" -#include "manager.h" +#include "core/manager.h" namespace core { @@ -118,13 +119,14 @@ void Download::set_root_directory(const std::string& path) { // If the download is open, hashed and has completed chunks make // sure to verify that the download files are still present. - // + // // This should ensure that no one tries to set the destination // directory 'after' moving files. In cases where the user wants to // override this behavior the download must first be closed or // 'd.directory_base.set' may be used. - rak::file_stat file_stat; - torrent::FileList* file_list = m_download.file_list(); + + torrent::utils::FileStat file_stat; + torrent::FileList* file_list = m_download.file_list(); if (is_hash_checked() && file_list->completed_chunks() != 0 && diff --git a/src/core/manager.cc b/src/core/manager.cc index a3cd601d..b6f4959f 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -257,7 +257,7 @@ Manager::try_create_download(const std::string& uri, int flags, const command_li !is_network_uri(uri) && !is_magnet_uri(uri) && !is_data_uri(uri) && - !file_status_cache()->insert(uri, 0)) + !file_status_cache()->insert(uri)) return; // Adding download. diff --git a/src/main.cc b/src/main.cc index 19b57920..0e5c9ceb 100644 --- a/src/main.cc +++ b/src/main.cc @@ -13,7 +13,6 @@ #include #include #include -#include #ifdef HAVE_BACKTRACE #include @@ -564,7 +563,7 @@ handle_sigbus(int signum, siginfo_t* sa, [[maybe_unused]] void* ptr) { #else output << "Stack dump not enabled." << std::endl; #endif - output << std::endl << "Error: " << rak::error_number(sa->si_errno).c_str() << std::endl; + output << std::endl << "Error: " << std::strerror(sa->si_errno) << std::endl; const char* signal_reason; diff --git a/src/rpc/lua.cc b/src/rpc/lua.cc index 5311de92..2c4b56f7 100644 --- a/src/rpc/lua.cc +++ b/src/rpc/lua.cc @@ -1,5 +1,6 @@ #include "config.h" +#include #include #include #include @@ -10,7 +11,6 @@ #include #endif -#include #include #include #include @@ -419,12 +419,16 @@ execute_lua(LuaEngine* engine, rpc::target_type target_type, torrent::Object con } #else + torrent::Object -execute_lua(LuaEngine* engine, torrent::Object const& rawArgs, int flags) { +execute_lua([[maybe_unused]] LuaEngine* engine, [[maybe_unused]] torrent::Object const& rawArgs, [[maybe_unused]] int flags) { throw torrent::input_error("Lua support not enabled"); return torrent::Object(); } + LuaEngine::LuaEngine() {} LuaEngine::~LuaEngine() {} + #endif + } // namespace rpc diff --git a/src/rpc/scgi_task.cc b/src/rpc/scgi_task.cc index c151b0e6..6dd7924a 100644 --- a/src/rpc/scgi_task.cc +++ b/src/rpc/scgi_task.cc @@ -2,7 +2,6 @@ #include "rpc/scgi_task.h" -#include #include #include #include @@ -59,7 +58,7 @@ SCgiTask::event_read() { int bytes = ::recv(m_fileDesc, m_position, m_buffer_size - (m_position - m_buffer), 0); if (bytes <= 0) { - if (bytes == 0 || !rak::error_number::current().is_blocked_momentary()) + if (bytes == 0 || !(errno == EAGAIN || errno == EINTR)) close(); return; @@ -194,7 +193,7 @@ SCgiTask::event_write() { #endif if (bytes == -1) { - if (!rak::error_number::current().is_blocked_momentary()) + if (!(errno == EAGAIN || errno == EINTR)) close(); return; diff --git a/src/signal_handler.cc b/src/signal_handler.cc index 0d892516..1ec193f3 100644 --- a/src/signal_handler.cc +++ b/src/signal_handler.cc @@ -1,44 +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 "rak/error_number.h" #include "signal_handler.h" #ifdef __sun__ @@ -80,7 +47,7 @@ SignalHandler::set_handler(unsigned int signum, slot_void slot) { sa.sa_handler = &SignalHandler::caught; if (sigaction(signum, &sa, NULL) == -1) - throw std::logic_error("Could not set sigaction: " + std::string(rak::error_number::current().c_str())); + throw std::logic_error("Could not set sigaction: " + std::string(std::strerror(errno))); else m_handlers[signum] = slot; } @@ -97,7 +64,7 @@ SignalHandler::set_sigaction_handler(unsigned int signum, handler_slot slot) { sigemptyset(&sa.sa_mask); if (sigaction(signum, &sa, NULL) == -1) - throw std::logic_error("Could not set sigaction: " + std::string(rak::error_number::current().c_str())); + throw std::logic_error("Could not set sigaction: " + std::string(std::strerror(errno))); } void diff --git a/src/utils/file_status_cache.cc b/src/utils/file_status_cache.cc index 8d1c996b..3cbf54d4 100644 --- a/src/utils/file_status_cache.cc +++ b/src/utils/file_status_cache.cc @@ -1,50 +1,16 @@ -// 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 "file_status_cache.h" namespace utils { bool -FileStatusCache::insert(const std::string& path, int flags) { - rak::file_stat fs; +FileStatusCache::insert(const std::string& path) { + torrent::utils::FileStat fs; // 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 @@ -71,7 +37,7 @@ FileStatusCache::prune() { iterator itr = begin(); while (itr != end()) { - rak::file_stat fs; + torrent::utils::FileStat fs; iterator tmp = itr++; if (!fs.update(rak::path_expand(tmp->first)) || tmp->second.m_mtime != (uint32_t)fs.modified_time()) diff --git a/src/utils/file_status_cache.h b/src/utils/file_status_cache.h index fe3e00b4..3718d938 100644 --- a/src/utils/file_status_cache.h +++ b/src/utils/file_status_cache.h @@ -1,37 +1,3 @@ -// 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 - - #ifndef RTORRENT_UTILS_FILE_STATUS_CACHE_H #define RTORRENT_UTILS_FILE_STATUS_CACHE_H @@ -69,7 +35,7 @@ public: // 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, int flags); + bool insert(const std::string& path); // Add a function for pruning a sorted list of paths.