예제 #1
0
bool CRepo::parse()
{
	assert(!tmpFile.empty());
	if (tmpFile.empty()) {
		LOG_DEBUG("tmpfile empty, repo not initialized?");
		return false;
	}
	LOG_DEBUG("%s", tmpFile.c_str());
	FILE* f = fileSystem->propen(tmpFile, "rb");
	if (f == nullptr) {
		LOG_ERROR("Could not open %s", tmpFile.c_str());
		return false;
	}
	gzFile fp = gzdopen(fileno(f), "rb");
	if (fp == Z_NULL) {
		fclose(f);
		LOG_ERROR("Could not gzdopen %s", tmpFile.c_str());
		return false;
	}

	char buf[IO_BUF_SIZE];
	sdps.clear();
	while ((gzgets(fp, buf, sizeof(buf))) != Z_NULL) {
		for (unsigned int i = 0; i < sizeof(buf); i++) {
			if (buf[i] == '\n') {
				buf[i] = 0;
				break;
			}
		}

		const std::string line = buf;
		std::vector<std::string> items = tokenizeString(line, ',');
		if (items.size() < 4) {
			LOG_ERROR("Invalid line: %s", line.c_str());
			continue;
		}

		// create new repo from url
		CSdp sdptmp = CSdp(items[0], items[1], items[3], items[2], repourl);
		rapid->addRemoteSdp(sdptmp);
	}
	int errnum = Z_OK;
	const char* errstr = gzerror(fp, &errnum);
	switch (errnum) {
		case Z_OK:
		case Z_STREAM_END:
			break;
		default:
			LOG_ERROR("%d %s\n", errnum, errstr);
	}
	gzclose(fp);
	fclose(f);
	return true;
}
예제 #2
0
bool CRepo::parse()
{
	LOG_DEBUG("%s",tmpFile.c_str());
	gzFile fp=gzopen(tmpFile.c_str(), "r");
	if (fp==Z_NULL) {
		LOG_ERROR("Could not open %s",tmpFile.c_str());
		return false;
	}

	char buf[IO_BUF_SIZE];
	sdps.clear();
	while ((gzgets(fp, buf, sizeof(buf)))!=Z_NULL) {
		for (unsigned int i=0; i<sizeof(buf); i++) {
			if (buf[i]=='\n') {
				buf[i]=0;
				break;
			}
		}

		std::string tmp=buf;
		std::string shortname=getStrByIdx(tmp,',',0);
		std::string md5=getStrByIdx(tmp,',',1);
		std::string depends=getStrByIdx(tmp,',',2);
		std::string name=getStrByIdx(tmp,',',3);
		if (shortname.size()>0) { //create new repo from url
			CSdp sdptmp=CSdp(shortname, md5, name, depends, repourl);
			rapid->addRemoteDsp(sdptmp);
		}
	}
	int errnum=Z_OK;
	const char* errstr = gzerror(fp, &errnum);
	switch(errnum) {
	case Z_OK:
	case Z_STREAM_END:
		break;
	default:
		LOG_ERROR("%d %s\n", errnum, errstr);
	}
	gzclose(fp);
	return true;
}