Exemple #1
0
void init_disk_cache(bool firstTime)
{
#ifdef ENABLE_SQLITE_DISK_INDEX
	if (dci==NULL) {
		memset(&index_scan_state,0,sizeof(index_scan_state));
		load_index_scan_state();
		dci = new KSqliteDiskCacheIndex;
		char *file_name = getCacheIndexFile();
		KStringBuf sqliteIndex;
		sqliteIndex << file_name << ".sqt";
		free(file_name);
		KFile fp;
		if (fp.open(sqliteIndex.getString(),fileRead)) {
			fp.close();
			if (dci->open(sqliteIndex.getString())) {
				dci->start(ci_load,NULL);
			} else {
				klog(KLOG_ERR,"recreate the disk cache index database\n");
				dci->close();
				unlink(sqliteIndex.getString());
				dci->create(sqliteIndex.getString());
				rescan_disk_cache();
			}
		} else {
			dci->create(sqliteIndex.getString());
			m_thread.start(NULL,load_cache_index);
		}
	}
#else
	memset(&index_scan_state,0,sizeof(index_scan_state));
	load_index_scan_state();
	m_thread.start(NULL,load_cache_index);
#endif
}
Exemple #2
0
int create_file_index(const char *file,void *param)
{
	KStringBuf s;
	cor_result result = cor_failed;
	KHttpObject *obj;
	s << (char *)param << PATH_SPLIT_CHAR << file;
	char *file_name = s.getString();
	KFile fp;
	if (!fp.open(s.getString(),fileRead)) {
		fprintf(stderr,"cann't open file[%s]\n",s.getString());
		return 0;
	}
	if (recreate_start_time>0) {
		INT64 t = fp.getCreateTime();
		if (t>recreate_start_time) {
			klog(KLOG_DEBUG,"file [%s] is new file t=%d\n",file_name,(int)(t-recreate_start_time));
			return 0;
		}
	}
	/////////[139]
	KHttpObjectFileHeader header;
	if(fp.read((char *)&header,sizeof(KHttpObjectFileHeader))!=sizeof(KHttpObjectFileHeader)){
		fprintf(stderr,"cann't read head size [%s]\n",file_name);
		goto failed;
	}
	obj = new KHttpObject;
	memcpy(&obj->index,&header.index,sizeof(obj->index));
	/////////[140]
	result = create_http_object(&fp,obj,file_name);
	if (result==cor_success) {
#ifdef ENABLE_DB_DISK_INDEX
		if (dci) {
			dci->start(ci_add,obj);
		}
#endif
		load_count++;
#if 0
		if (rebuild_cache_hash) {
			char *file_name2 = obj->getFileName();
			if (file_name2) {
				if (strcmp(file_name,file_name2)!=0) {
					if (rename(file_name,file_name2)!=0) {
						rebuild_cache_files.insert(std::pair<std::string,std::string>(file_name,file_name2));
					}
					/////////[141]
				}
				free(file_name2);
			}
		}
#endif
	}
	obj->release();
failed:
	fp.close();
	if (result==cor_failed) {
		klog(KLOG_NOTICE,"create http object failed,remove file[%s]\n",file_name);
		unlink(file_name);		
	}
	return 0;
}
Exemple #3
0
bool load_index_scan_state()
{
	KStringBuf s;
	get_index_scan_state_filename(s);
	KFile fp;
	if (!fp.open(s.getString(),fileRead)) {
		return false;
	}
	bool result = true;
	if (sizeof(index_scan_state_t) != fp.read((char *)&index_scan_state,sizeof(index_scan_state_t))) {
		result = false;
	}
	fp.close();
	return result;
}
Exemple #4
0
bool KConfigBuilder::saveConfig() {
	KConfigBuilder builder;
#ifdef KANGLE_ETC_DIR
	string configFile = KANGLE_ETC_DIR;
#else
	string configFile = conf.path + "/etc";
#endif
	configFile += CONFIG_FILE;
	string tmpfile = configFile + ".tmp";
	string lstfile = configFile + ".lst";
	KFile fp;
	if(!fp.open(tmpfile.c_str(),fileWrite)){
		fprintf(stderr, "cann't open configfile[%s] for write\n",
				tmpfile.c_str());
		return false;
	}
	stringstream s;
	builder.build(s);
	s << "\r\n" << CONFIG_FILE_SIGN;
	bool result = false;
	if ((int)s.str().size() == fp.write(s.str().c_str(), s.str().size())) {
		result = true;
	}
	fp.close();
	if (!result) {
		fprintf(stderr,"cann't write sign string\n");
		return false;
	}
	unlink(lstfile.c_str());
	rename(configFile.c_str(),lstfile.c_str());
	rename(tmpfile.c_str(),configFile.c_str());
	if (conf.mergeFiles.size()>0) {
		//remove the merge config files.
		std::list<std::string>::iterator it;
		for(it=conf.mergeFiles.begin();it!=conf.mergeFiles.end();it++){
			unlink((*it).c_str());
		}
		conf.mergeFiles.clear();
		std::string errMsg;
		conf.gvm->saveConfig(errMsg);
	}
	//°Ñvh.xmlÖØÃüÃû
	string file = conf.path;
	file += VH_CONFIG_FILE;
	string oldfile = file + ".old";
	rename(file.c_str(),oldfile.c_str());
	return true;
}