bool CSdp::download(){ if (downloaded) //allow download only once of the same sdp return true; filename=fileSystem->getSpringDir() + PATH_DELIMITER+"packages"+PATH_DELIMITER; DEBUG_LINE("%s\n",filename.c_str()); if (!fileSystem->directoryExists(filename)){ fileSystem->createSubdirs(filename); } int count=0; filename += this->md5 + ".sdp"; CFileSystem::FileData tmp; md5AtoI(md5,tmp.md5); std::list<CFileSystem::FileData*> files; if (!fileSystem->parseSdp(filename,files)){ //file isn't avaiable, download it IDownload dl(url + "/packages/" + md5 + ".sdp", filename); httpDownload->download(dl); fileSystem->parseSdp(filename,files); //parse downloaded file } std::list<CFileSystem::FileData*>::iterator it; /* CHttpDownload* tmp=httpDownload; //FIXME: extend interface? tmp->setCount(files.size()); */ int i=0; it=files.begin(); while (it!=files.end()){ i++; std::string tmpmd5=""; md5ItoA((*it)->md5, tmpmd5); std::string filename=tmpmd5.substr(2); filename.append(".gz"); std::string path("/pool/"); path += tmpmd5.at(0); path += tmpmd5.at(1); path += "/"; std::string file=fileSystem->getSpringDir() + path + filename; //absolute filename if (!fileSystem->directoryExists(fileSystem->getSpringDir()+path)){ fileSystem->createSubdirs(fileSystem->getSpringDir()+path); } if (!fileSystem->fileIsValid(*it,file)){ //add invalid files to download list count++; (*it)->download=true; }else{ (*it)->download=false; } if (i%10==0) printf("\r%d/%d checked",i,(int)files.size()); it++; } printf("\r%d/%d need to download %d files\n",i,(unsigned int)files.size(),count); if (count>0){ //FIXME httpDownload->setCount(count); downloaded=downloadStream(this->url+"/streamer.cgi?"+this->md5,files); files.clear(); printf("Sucessfully downloaded %d files: %s %s\n",count,shortname.c_str(),name.c_str()); }else{ printf("Already downloaded: %s\n", shortname.c_str()); downloaded=true; } return downloaded; }
bool CSdp::download() { if (downloaded) //allow download only once of the same sdp return true; filename=fileSystem->getSpringDir() + PATH_DELIMITER+"packages"+PATH_DELIMITER; LOG_DEBUG("%s",filename.c_str()); if (!fileSystem->directoryExists(filename)) { fileSystem->createSubdirs(filename); } int count=0; filename += this->md5 + ".sdp"; const std::string tmpFile = filename + ".tmp"; std::list<FileData*> files; bool rename = false; if (!fileSystem->fileExists(filename)) { //.sdp isn't avaiable, download it IDownload dl(tmpFile); dl.addMirror(url + "/packages/" + this->md5 + ".sdp"); httpDownload->download(&dl); fileSystem->parseSdp(tmpFile,files); //parse downloaded file rename = true; } else { fileSystem->parseSdp(filename,files); //parse downloaded file } std::list<FileData*>::iterator it; HashMD5 md5= HashMD5(); FileData tmp=FileData(); int i=0; for(it = files.begin(); it!=files.end(); ++it) { //check which file are available on local disk -> create list of files to download i++; md5.Set((*it)->md5, sizeof((*it)->md5)); std::string file; fileSystem->getPoolFilename(md5.toString(), file); if (!fileSystem->fileExists(file)) { //add non-existing files to download list count++; (*it)->download=true; } else { (*it)->download=false; } if (i%10==0) { LOG_DEBUG("\r%d/%d checked",i,(int)files.size()); } } LOG_DEBUG("\r%d/%d need to download %d files",i,(unsigned int)files.size(),count); std::string root = fileSystem->getSpringDir(); root += PATH_DELIMITER; root += "pool"; root += PATH_DELIMITER; if (!createPoolDirs(root)) { LOG_ERROR("Creating pool directories failed"); count = 0; } if (count>0) { downloaded=downloadStream(this->url+"/streamer.cgi?"+this->md5,files); LOG_DEBUG("Sucessfully downloaded %d files: %s %s",count,shortname.c_str(),name.c_str()); } else { LOG_DEBUG("Already downloaded: %s", shortname.c_str()); downloaded=true; } for(it = files.begin(); it!=files.end(); ++it) { //free memory delete *it; } if ((rename) && (!fileSystem->Rename(tmpFile, filename))) { LOG_ERROR("Couldn't rename %s to %s", tmpFile.c_str(), filename.c_str()); } return downloaded; }