bool CRapidDownloader::download_name(IDownload* download, int reccounter, std::string name) { LOG_DEBUG("%s %s", name.c_str(), download->name.c_str()); if (reccounter > 10) return false; LOG_DEBUG("Using rapid to download %s", download->name.c_str()); std::set<std::string> downloaded; for (CSdp& sdp : sdps) { if (!match_download_name(sdp.getName(), name.empty() ? download->name : name)) continue; if (downloaded.find(sdp.getMD5()) != downloaded.end()) // already downloaded, skip (i.e. stable entries are // twice in versions.gz) continue; downloaded.insert(sdp.getMD5()); LOG_DOWNLOAD(sdp.getName().c_str()); if (!sdp.download(download)) { return false; } if (sdp.getDepends().empty()) continue; if (!download_name(download, reccounter + 1, sdp.getDepends())) { return false; } } return true; }
bool CSdp::downloadStream(std::string url,std::list<CFileSystem::FileData>& files) { CURL* curl; curl = curl_easy_init(); if (curl) { CURLcode res; LOG_INFO("Using rapid"); LOG_DOWNLOAD(url.c_str()); curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); std::list<CFileSystem::FileData>::iterator it; int buflen=files.size()/8; if (files.size()%8!=0) buflen++; char* buf=(char*)malloc(buflen); //FIXME: compress blockwise and not all at once memset(buf,0,buflen); int destlen=files.size()*2; DEBUG_LINE("%d %d %d\n",(int)files.size(),buflen,destlen); int i=0; for (it=files.begin(); it!=files.end(); ++it) { if ((*it).download==true) buf[i/8] = buf[i/8] + (1<<(i%8)); i++; } char* dest=(char*)malloc(destlen); gzip_str(buf,buflen,dest,&destlen); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_streamed_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); curl_easy_setopt(curl, CURLOPT_USERAGENT, PR_DOWNLOADER_AGENT); globalFiles=&files; curl_easy_setopt(curl, CURLOPT_FAILONERROR, true); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, dest); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,destlen); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func); res = curl_easy_perform(curl); free(dest); /* always cleanup */ curl_easy_cleanup(curl); if (res!=CURLE_OK) { LOG_ERROR("%s\n",curl_easy_strerror(res)); return false; } } return true; }
bool CRapidDownloader::download_name(const std::string& longname, int reccounter) { LOG_DEBUG("%s",longname.c_str()); std::list<CSdp>::iterator it; if (reccounter>10) return false; LOG_DEBUG("Using rapid"); for (it=sdps.begin(); it!=sdps.end(); ++it) { if (match_download_name((*it).getName(),longname)) { LOG_DOWNLOAD((it)->getName().c_str() ); if (!(*it).download()) return false; if ((*it).getDepends().length()>0) { if (!download_name((*it).getDepends(),reccounter+1)) return false; } return true; } } return false; }
bool CRapidDownloader::download_name(IDownload* download, int reccounter,std::string name) { LOG_DEBUG("%s %s",name.c_str(),download->name.c_str()); std::list<CSdp>::iterator it; if (reccounter>10) return false; LOG_DEBUG("Using rapid"); for (it=sdps.begin(); it!=sdps.end(); ++it) { if (match_download_name((*it).getName(),name.length() == 0 ? download->name : name )) { LOG_DOWNLOAD((it)->getName().c_str() ); if (!(*it).download(download)) return false; if ((*it).getDepends().length()>0) { if (!download_name(download,reccounter+1,(*it).getDepends())) return false; } return true; } } return false; }