bool Context::dataPresentInSeedDir(libtorrent::torrent_info const& _torrent_info) { BTG_MENTER(logWrapper(), "dataPresentInSeedDir(torrent_info)", ""); bool status = false; libtorrent::torrent_info::file_iterator iter; // Try to find any file. for (iter = _torrent_info.begin_files(); iter != _torrent_info.end_files(); iter++) { libtorrent::file_entry const& fe = *iter; // The full path. boost::filesystem::path const& file_path = fe.path; if (boost::filesystem::exists(seedDir_ / file_path)) { // Check whether we have the same directory as file name in torrent. // If so, we can't use the seedDir anyway. if (boost::filesystem::is_directory(seedDir_ / file_path)) { BTG_MNOTICE(logWrapper(), "dataPresentInSeedDir: torrent file '" << file_path.string() << "' is a directory, can't use seedDir."); } else { status = true; BTG_MNOTICE(logWrapper(), "dataPresentInSeedDir: found torrent file '" << file_path.string() << "'."); } break; } } BTG_MEXIT(logWrapper(), "dataPresentInSeedDir(torrent_info)", status); return status; }
bool Context::torrentInfoToFiles(libtorrent::torrent_info const& _tinfo, std::vector<std::string> & _output) const { BTG_MENTER(logWrapper(), "torrentInfoToFiles", ""); bool status = true; try { libtorrent::torrent_info::file_iterator iter; for (iter = _tinfo.begin_files(); iter != _tinfo.end_files(); iter++) { libtorrent::file_entry const& fe = *iter; BTG_MNOTICE(logWrapper(), fe.path.string()); _output.push_back(fe.path.string()); } } catch (std::exception& e) { BTG_ERROR_LOG(logWrapper(), "libtorrent exception (torrentInfoToFiles): " << e.what() ); status = false; } if (_output.size() == 0) { // Torrents with no files are not ok. BTG_ERROR_LOG(logWrapper(), "torrentInfoToFiles, attempt to load torrent with no files in it."); status = false; } BTG_MEXIT(logWrapper(), "torrentInfoToFiles", status); return status; }
bool Context::dataPresentInSeedDir(libtorrent::torrent_info const& _torrent_info) { BTG_MENTER(logWrapper(), "dataPresentInSeedDir(torrent_info)", ""); bool status = true; // Fix of bug #10064 // Try to find ANY file in seed dir before give up bool found = false; libtorrent::torrent_info::file_iterator iter; // Find and count the files. for (iter = _torrent_info.begin_files(); iter != _torrent_info.end_files(); iter++) { libtorrent::file_entry const& fe = *iter; // The full path. boost::filesystem::path file_path = fe.path; // Only the file name. std::string filename = file_path.leaf(); // Get the first directory name, if it exists. if (!file_path.branch_path().empty()) { file_path = file_path.branch_path(); } // Fix of bug #11575 / #12055 // Check if the found file path is a directory. // If its not, then its just files in the seed // directory. try { if (boost::filesystem::exists(seedDir_ / file_path) && boost::filesystem::is_directory(seedDir_ / file_path)) { file_path = seedDir_ / file_path; } else { file_path = seedDir_; } } catch(std::exception& e) { BTG_ERROR_LOG(logWrapper(), "Got exception from boost::filesystem, is_directory: " << e.what()); status = false; break; } BTG_MNOTICE(logWrapper(), "Using directory '" << file_path.string() << "'"); BTG_MNOTICE(logWrapper(), "Checking file '" << filename << "'"); try { if (find_file(boost::filesystem::path(file_path), filename)) { found = true; break; } } catch(std::exception& e) { BTG_ERROR_LOG(logWrapper(), "Got exception from find_file: " << e.what()); status = false; break; } } BTG_MEXIT(logWrapper(), "dataPresentInSeedDir(torrent_info)", (status && found) ); return status && found; }