| 72 | } |
| 73 | |
| 74 | void DownloadPool::addTask(const std::string &url, const std::string& output) |
| 75 | { |
| 76 | std::string formatedPath = output; |
| 77 | std::replace(formatedPath.begin(), formatedPath.end(), DIR_SEP_R, DIR_SEP); |
| 78 | #ifndef NDEBUG |
| 79 | struct stat buffer; |
| 80 | if (stat (formatedPath.c_str(), &buffer) == 0) |
| 81 | { |
| 82 | return; |
| 83 | } |
| 84 | #endif |
| 85 | |
| 86 | std::string uid = url + output; |
| 87 | bool existed = false; |
| 88 | Task task(url, formatedPath); |
| 89 | m_mtx.lock(); |
| 90 | if (!(existed = (m_urls.find(uid) != m_urls.cend()))) |
| 91 | { |
| 92 | m_urls.insert(uid); |
| 93 | m_queue.push(task); |
| 94 | } |
| 95 | m_mtx.unlock(); |
| 96 | |
| 97 | if (existed) |
| 98 | { |
| 99 | #ifndef NDEBUG |
| 100 | printf("URL Existed: %s", url.c_str()); |
| 101 | #endif |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | void DownloadPool::setNoMoreTask() |
| 106 | { |