`
hulianwang2014
  • 浏览: 690401 次
文章分类
社区版块
存档分类
最新评论
  • bcworld: 排版成这样,一点看的欲望都没有了
    jfinal

代码

 
阅读更多
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define PCAP_PATH_NAME "/fwlog/bugreport/pcap/"
map<int, vector<string>> file_all;
void initial_map()
{
DIR *dir_content;
DIR *dir_file;
struct dirent* dir_ent;
struct dirent* dir_ent_file;
vector<string> tmp;
dir = opendir(PCAP_PATH_NAME);
if(dir == NULL)
{
prinf("open dir fail\n");
return 0;
}
while((dir_ent = readdir(dir)) != NULL)
{
if(dir_ent->d_type == mulu)
{
string tmp = PCAP_PATH_NAME;
tmp +="/";
tmp +=dir_ent->d_name;
dir_file = opendir(tmp.c_str());
if(dir_file == NULL)
{
printf("open file dir fail\n");
return 0;
}
while((dir_ent_file = readdir(dir_file)) != NULL)
{
tmp.push_back(string(dir_ent_file->d_name));
}
}
int sid = atoi(dir_ent->d_name);
file_all.insert(pair<int vector<string>>(sid,tmp);
tmp.clear();
}
}
bool find_sid_dir(int sid)
{
map<int, vector<string>>::iterator it = file_all.find(sid);
if(it != file_all.end());
{
return true;
}
else
{
return false;
}
}
map的大小
map.size();
if(file_all.size() >= 100)
int find_dir_earlist()
{
string str_ret = "";
struct stat buf;
time_t earlist;
map<int, vector<string>>::iterator it;
for(it = file_all.begin(); it != file_all.end(); it++)
{
string dir_name = PCAP_PATH_NAME;
dir_name += "/";
dir_name += atoi(it->first);
stat(dir_name.c_str(), &buf);
if(it == file_all.begin())
{
earlist = buf.st_mtime;
str_ret = dir_name;
}
if(buf.st_mtime < earlist)
{
earlist = buf.st_mtime;
str_ret = dir_name;
}
}
return it->first;
}
//删除文件夹用我自己的调用system函数来执行
//删除sid目录
调用file_all.erase(sid);
mkdir//创建目录
//创建成功加入到file_all这个map中
//失败回滚
int file_count(int sid, string &ear_file)
{
int count = 0;
time_t earlist;
struct stat buf;
stringstream ss;
string out;
map<int, vector<string>>::iterator it;
for(it = file_all.begin(); it != file_all.end(); it++)
{
string file_path = "PCAP_PATH_NAME";
file_path +="/";
ss<<it->first;
ss>>out;
file_path += out;
count += it->second.size();
vector<string>::iterator it1;
for(it1 = it->second.begin(); it1 != it->second.end(); it++)
{
stat(file_path.c_str(),&buf);
if(it1 == it->second.begin() && it == file_all.begin())
{
ear_file = file_path;
earlist = buf.st_mtime;
}
else
{
if(earlist > buf.st_mtime)
{
ear_file = file_path;
earlist = buf.st_mtime;
}
}
}


}
return count;
}
if(file_count() > 100)
{
//删除文件
//创建文件,加入map,写文件
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics