::CORBA::Long FiUpdateMgrImpl::getMD5FromFile(const char* fileName, ::CORBA::String_out md5Value) { string fullName = ""; string localMD5Val = ""; char pathTmp[256] = {0}; version_t locVer; if (!fileName) { ut_err("argv fileName is NULL!\n"); return 0; } memset(&locVer, 0, sizeof(version_t)); if (getVerFromName(fileName, &locVer) < 0) { ut_err("get ver from name fail?\n"); return 0; } //eg:sobey/fics/download/fics_v1.0.0_2015.09.19_4008/server_v1.0.0_2015.09.19_4008_64_Linux2.6.tar.gz sprintf(pathTmp, "%sfics_%s_%s_%s/", _PATH_PKG_DL, locVer.version, locVer.date, locVer.patchNo); fullName += pathTmp; fullName += fileName; if (getMD5FromLocal(fullName.c_str(), localMD5Val) < 0)//from cache not file { ut_err("get md5 fail\n"); } md5Value = CORBA::string_dup(localMD5Val.c_str()); return 0; }
int getLastVerFromHis(version_t *ver, const char *path) { FILE *fp = NULL; char cmd[512] = {0}; char line[256] = {0}; int ret = -1; if (!ver || !path) { ut_err("ver is null\n"); goto err; } //tail -1 path sprintf(cmd, "tail -1 %s", path); if (NULL ==(fp = popen(cmd, "r"))) { ut_err("popen fail\n"); goto err; } while (fscanf(fp, "%[^\n]s", line) == 1) { fgetc(fp); } ret = pclose(fp); sscanf(line, "%*s %s %s %s", ver->version, ver->date, ver->patchNo); return ret; err: return ret; }
int getVerFromName(const char *fileName, version_t *ver) { char buff[512] = {0}; char *date = NULL; char *version = NULL; char *patchNo = NULL; char *end = NULL; if (!fileName || !ver) { ut_err("filename or ver is null \n"); goto err; } strcpy(buff, fileName); version = strstr(buff, "_v"); if (!version) { ut_err("get veresion fail\n"); goto err; } version ++; date = strchr(version, '_'); if (!date) { ut_err("get date fail\n"); goto err; } *date = '\0'; date ++; patchNo = strchr(date, '_'); if (!patchNo) { ut_err("get patch no fail\n"); goto err; } *patchNo = '\0'; patchNo ++; end = strchr(patchNo, '_'); if (end) { *end = '\0'; } sprintf(ver->version, "%s", version); sprintf(ver->date, "%s", date); sprintf(ver->patchNo, "%s", patchNo); return 0; err: return -1; }
/** * @brief 下载loss的包 version -> netVer ;date -> lossPatchs[i][1] fics_v1.0.0_2015.10.10_4005 * * @param netVer * @param lossPatchs * * @return */ int downLossPatch(version_t *netVer, patchSet_t lossPatchs) { int i=0; int ret = 0; char dstFile[512]={0}; string tmpDate; string curType; // sprintf(srcFile, "/sobey/fics/download/fics_%s_", netVer->version);//正则 re // sprintf(dstFile, "/sobey/fics/update/fics_%s_", netVer->version);//正则 re for (i =0; i<BASEINTERVAL; i++) { if (lossPatchs[i][0]!=0) { #if 1 ret = FiUpdateAssistant::getinstance()->downLossPkg(netVer, lossPatchs[i][1], mkVer(getCurBaseVer(atoi(netVer->patchNo)), i));//down over #else ret = FiUpdateAssistant::getinstance()->downloadFile(ip, srcFile, dstFile); #endif long2Date(lossPatchs[i][1], tmpDate);//set to str date sprintf(dstFile, "fics_%s_%s_%d", netVer->version, tmpDate.c_str(), mkVer(getCurBaseVer(atoi(netVer->patchNo)), i));//正则 re if (ret == 0) { ut_dbg("download file %s success\n", dstFile); lossPatchs[i][0] = 0; } else { ut_err("download file %s fail\n", dstFile); ret = -1; // i--;//一直下载不下来则退出 重新查询版本信息 } } } i = 0; //check patch while (!lossPatchs[i++][0] && i<BASEINTERVAL){}; if (i < BASEINTERVAL) { ret = -2; ut_err("patch:%d is not be downed.\n", i); } else { ret = 0; ut_dbg("down all patchs complete\n"); } return ret; }
int getPkgList(char const * path, char const * prefix, char const *suffix, const char *version, vector<string> & pkgList) { char cmdBuf[256] = {0}; char tmppath[256]={0}; char *fileName = NULL; FILE *fp = NULL; #ifdef WIN32 sprintf(cmdBuf, "dir /b \"%s\\%s_%s_*%s\"", path, prefix, version, suffix); #else sprintf(cmdBuf, "find %s -name \'%s_%s_*%s\'", path, prefix, version, suffix); #endif if (NULL == (fp = popen(cmdBuf, "r"))) { ut_err("popen fail\n"); goto err; } while (fscanf(fp, "%[^\n]s", tmppath) == 1) { fgetc(fp); fileName = basename(tmppath); pkgList.push_back(fileName); } pclose(fp); //find ./ -name 'server_v1.0.0_*.tar.gz' return 0; err: return -1; }
int getMD5FromLocal(const char *fileName, string &localMd5) { char cmdBuf[512] = {0}; char localMd5Buf[256] = {0}; FILE *fp = NULL; if (!fileName) { ut_err("file name is null\n"); goto err; } if (getMD5FromCache(fileName, localMd5) == 0) { return 0; } #ifdef WIN32 sprintf(cmdBuf, "md5sums -u %s", fileName); #else sprintf(cmdBuf, "md5sum %s", fileName); #endif if (NULL ==(fp = popen(cmdBuf, "r"))) { ut_err("popen fail\n"); goto err; } if (fscanf(fp, "%[^ ]s", localMd5Buf) != 1)//6345b3f685ceefa3630bca9571b17534 { pclose(fp); goto err; } pclose(fp); if (strlen(localMd5Buf) < 32) { ut_err("md5 fail\n"); goto err; } localMd5 = localMd5Buf; if (addEleMD52Cache(fileName, localMd5) < 0) { ut_err("update md5 cache fail\n"); } return 0; err: return -1; }
int genHashFromHis(const char *path, string & hashValue) { vector<string> opList; FILE *fp = NULL; char buf[LEN_BUF] = {0}; int r; string keySum; unsigned char md[16]; int i; char tmp[3]={ '\0' },md5[33]={ '\0' }; fp = fopen(path, "r"); if (!fp) { ut_err("open fail\n"); goto err; } while ((r = fscanf(fp, "%s", buf)) == 1) { if (buf[0] == '#') { if (fscanf(fp, "%*[^\n]\n") < 0) { ut_err("skip # fail\n"); goto err; } continue; } r = fscanf(fp, "%*[ ]%[^\n]s", buf);//skip space huiche opList.push_back(buf); keySum += buf; } //利用opList生成MD5值,作为hash值 供客户端查询 // MD5(keySum.c_str(), strlen (keySum.c_str()), md);//mark for (i = 0; i < 16; i++) { sprintf(tmp, "%2.2x" , md[i]); strcat(md5, tmp); } hashValue = md5; return 0; err: return -1; }
void *heartHandler(void *params) { while(1) { sleep(60); if (sendHello()<0) { ut_err("send hello fail\n"); } } return NULL; }
int record2History(const char *fileName) { version_t curVer; if (!fileName) { ut_err("file name is null\n"); return -1; } memset(&curVer, 0, sizeof(version_t)); getVerFromName(fileName, &curVer); addVer2His(&curVer, HISTORY); return 0; }
bool untargz(const char *src, const char *dst) { char cmdBuf[512]; int suffixPos = strlen(".tar.gz"); int len = 0; #ifdef WIN32 string gzFile; char *p; #endif if (!src || !dst) { ut_err("src dst is null\n"); goto err; } len = strlen(src); if (strcmp(&src[len-suffixPos], ".tar.gz")!=0) { ut_err("this is not a tar.gz file.\n"); goto err; } #ifdef WIN32 sprintf(cmdBuf, "\"%s7z.exe\" x \"%s\" -o \"%s\"", G.exe, src, dst); system(cmdBuf); gzFile = src; p = strstr((char *)gzFile.c_str(), ".gz"); *p = '\0'; sprintf(cmdBuf, "del %s%s", G.exe, gzFile.c_str()); system(cmdBuf); sprintf(cmdBuf, "\"%s7z.exe\" x \"%s\" -o \"%s\"", G.exe, gzFile.c_str(), dst); system(cmdBuf); #else sprintf(cmdBuf, "tar -zxvf %s -C %s", src, dst); #endif system(cmdBuf); return true; err: return false; }
bool unzip(const char* src, const char *dst) { char cmdBuf[512]; int suffixPos = strlen(".zip"); int len = 0; if (!src || !dst) { ut_err("src dst is null\n"); goto err; } len = strlen(src); if (strcmp(&src[len-suffixPos], ".zip")!=0) { ut_err("this is not a zip file.\n"); goto err; } sprintf(cmdBuf, "unzip -o %s -d %s", src, dst); system(cmdBuf); return true; err: return false; }
int addVer2His(version_t *newVer, const char * path) { FILE *fp = NULL; char curOpVer[LEN_SHORT]; if (!newVer || !path) { ut_err("newVer or path is NULL\n"); goto err; } sprintf(curOpVer, "fics %s %s %s\n", newVer->version, newVer->date, newVer->patchNo); fp = fopen(path, "a+"); if (!fp) { ut_err("file is not exist\n"); goto err; } fputs(curOpVer, fp); fclose(fp); return 0; err: return -1; }
void nc_static_checks (void) { struct trans *t; struct ls *n; for (n = u.net.trans.next; n; n = n->next) { t = ls_i (struct trans, n, nod); if (t->pre.deg == 0 && t != u.net.t0 && t->post.deg != 0) { ut_warn ("%s is not restricted", t->name); } } ASSERT (u.net.t0); if (u.net.t0->post.deg == 0) ut_err ("No initial marking!"); }
int init_helloType(helloType_t *hello) { if (!hello) { ut_err("hello is null\n"); return -1; } memset(hello, 0, sizeof(hello)); strcpy(hello->action, "action:hello"); strcpy(hello->version, "version:"); strcpy(hello->endPoint.ip, "ip:"); strcpy(hello->endPoint.port, "port:"); strcpy(hello->endPoint.nodeId, "nodeid:"); return 0; }
__USE_LIBASN int main(int argc, char *argv[]) { char buf[BUFSIZ]; mmatic *mm = mmatic_create(); xstr *xs = xstr_create("", mm); json *js = json_create(mm); while (fgets(buf, BUFSIZ, stdin)) xstr_append(xs, buf); ut *parsed = json_parse(js, xstr_string(xs)); if (ut_ok(parsed)) printf("%s", json_print(js, parsed)); else printf("%s\n", ut_err(parsed)); return 0; }
/** * @brief 将字符串 2014.05.10 转化为整数20140510 * * @param date * * @return */ long date2Long(const char *date) { long ldate = 0; if (!date) { ut_err("date is null\n"); return 0; } while (*date) { if (*date == '.') { date++; continue; } ldate *= 10; ldate +=*date - '0'; date++; } return ldate; }
/** Parse config file * @retval 0 success * @retval 1 syntax error * @retval 2 logic error * @retval 3 other error */ static int parse_config(struct mg *mg) { FILE *fp; xstr *xs; char buf[4096], *str; json *js; ut *cfg; /* read file contents, ignoring empty lines and comments */ fp = fopen(mg->options.conf_file, "r"); if (!fp) { dbg(0, "%s: fopen() failed: %s\n", mg->options.conf_file, strerror(errno)); return 3; } xs = xstr_create("{", mg->mmtmp); while (fgets(buf, sizeof buf, fp)) { str = pjf_trim(buf); if (!str || !str[0] || str[0] == '#') continue; xstr_append(xs, str); } xstr_append_char(xs, '}'); fclose(fp); /* parse config file as loose JSON */ js = json_create(mg->mmtmp); json_setopt(js, JSON_LOOSE, 1); cfg = json_parse(js, xstr_string(xs)); if (!ut_ok(cfg)) { dbg(0, "parsing config file failed: %s\n", ut_err(cfg)); return 1; } /* parse config */ return (parse_config_ut(mg, cfg) ? 2 : 0); }
int syncPkg() { /*----------------------------------------------------------------------------- * 1. ask which pkg should be downed. * 2. compare local pkg * 3. down pkg that I dont have *-----------------------------------------------------------------------------*/ patchSet_t patchs;//memset patchSet_t lossPatchs;//memset int i = 0; int ret = 1; memset(&patchs, 0, sizeof(patchSet_t)); memset(&lossPatchs, 0, sizeof(patchSet_t)); FiUpdateAssistant::getinstance()->queryPatchs(patchs); if (0 == FiUpdateAssistant::getinstance()->comparePatchs(&(FiUpdateAssistant::getinstance()->netVer), patchs, lossPatchs)) { ut_dbg("my patchs is the same as server, dont need to down\n"); } else { ut_dbg("I have lost some patchs waiting for downing\n"); i = 4; while (i-- && ret!=0) { if ((ret = downLossPatch(&(FiUpdateAssistant::getinstance()->netVer), lossPatchs)) < 0) { //lossPatchs changed string set; patchs2str(lossPatchs, set); ut_err("down file fail !!!! lost patch list:%s \n", set.c_str()); } } } return 0; }
/** * @brief 接收master/其他server 的心跳包,更新download下的当前zip全版本安装包。master只发心跳包,不接收(master是所有的源)。 * * @param params * * @return */ void* recvHelloHandler(void *params) { int s; struct sockaddr_in local_addr; version_t localVer; int err = -1; memset(&localVer, 0, sizeof(localVer)); s = socket(AF_INET, SOCK_DGRAM, 0); if (s == -1) { perror("socket()"); return (void *)-1; } memset(&local_addr, 0, sizeof(local_addr)); local_addr.sin_family = AF_INET; local_addr.sin_addr.s_addr = htonl(INADDR_ANY); local_addr.sin_port = htons(MCAST_PORT); /*绑定socket*/ err = bind(s,(struct sockaddr*)&local_addr, sizeof(local_addr)) ; if(err < 0) { ut_err("bind()fail errno[%d]\n", errno); return (void *)-2; } /*设置回环许可*/ int loop = 0;//禁止 err = setsockopt(s,IPPROTO_IP, IP_MULTICAST_LOOP,&loop, sizeof(loop)); if(err < 0) { ut_err("setsockopt():IP_MULTICAST_LOOP\n"); return (void *)-3; } struct ip_mreq mreq; /*加入广播组*/ mreq.imr_multiaddr.s_addr = inet_addr(MCAST_ADDR); /*广播地址*/ mreq.imr_interface.s_addr = htonl(INADDR_ANY); /*网络接口为默认*/ /*将本机加入广播组*/ err = setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP,&mreq, sizeof (mreq)); if (err < 0) { ut_err("setsockopt():IP_ADD_MEMBERSHIP\n"); return (void *)-4; } int addr_len = 0; helloType_t buff; int n = 0; while (1) { addr_len = sizeof(local_addr); memset(&buff, 0, sizeof(buff)); /*清空接收缓冲区*/ /*接收数据*/ n = recvfrom(s, &buff, sizeof(buff), 0,(struct sockaddr*)&local_addr, &addr_len); if( n == -1) { ut_err("recvfrom()\n"); } if (strcmp(buff.action, "action:hello") != 0 || buff.endPoint.type != LEADER) { continue; } /*打印信息*/ ut_dbg("Recv hello message from server:%s\n", buff.version); getLocalVersion(&localVer); version_t net; int ret; memset(&net, 0, sizeof(net)); char *version = strstr(buff.version, "_v");//version:fics_v2.1.0_2015.09.04 if (version)version++; char *date = strchr(version, '_'); if (date)*date++='\0'; char *patchNo = strchr(date, '_'); if (patchNo)patchNo++; if (version)strcpy(net.version, version); if (date)strcpy(net.date, date); if (patchNo)strcpy(net.patchNo, patchNo); ret = compareVersion(&localVer, &net); if ( ret!= 0 && ret!=1000000) { char *ip = strstr(buff.endPoint.ip, "ip:"); ip = ip+strlen("ip:"); char srcFile[256]={0}; char cmdBuf[250]={0}; sprintf(srcFile, "/sobey/fics/download/fics_%s_%s", net.version, net.date); if (patchNo)sprintf(srcFile+strlen(srcFile), "_%s", patchNo); strcat(srcFile, ".zip"); //down file ret = FiUpdateAssistant::getinstance()->downloadFile(ip, srcFile, srcFile); if (ret == 0) { ut_dbg("download file success\n"); //modify local patch_version char patchVerBuf[200]; sprintf(cmdBuf, "unzip %s -d %s", srcFile, _PATH_PKG_DL); system(cmdBuf);//unzip pkg writeLocalVer(&net); //overwrite patch_version } else { ut_err("download file fail\n"); sprintf(cmdBuf, "rm %s -rf", srcFile); system(cmdBuf); } } sleep(MCAST_INTERVAL); } /*退出广播组*/ err = setsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP,&mreq, sizeof (mreq)); close(s); return NULL; }
int sendHello() { int s; int err=0; helloType_t hello; version_t localVer; struct sockaddr_in mcast_addr; std::string localIp; init_helloType(&hello); memset(&localVer, 0, sizeof(version_t)); if (getCurLocalIp(localIp) < 0) { ut_err("get local ip fail\n"); return -1; } getLocalVersion(&localVer); s = socket(AF_INET, SOCK_DGRAM, 0); if (s == -1) { ut_err("socket() fail\n"); return -1; } //fics sprintf(hello.version+strlen(hello.version), "fics_%s_%s", localVer.version, localVer.date); strcat(hello.endPoint.ip, localIp.c_str()); sprintf(hello.endPoint.port+strlen(hello.endPoint.port), "%d", RPC_PORT); sprintf(hello.endPoint.nodeId+strlen(hello.endPoint.nodeId),"%d", umparams.master ? 0 : -1);//need to modify hello.endPoint.type = umparams.master == true ? LEADER : FOLLOWER; memset(&mcast_addr, 0, sizeof(mcast_addr));/*初始化IP多播地址为0*/ mcast_addr.sin_family = AF_INET; /*设置协议族类行为AF*/ mcast_addr.sin_addr.s_addr = inet_addr(MCAST_ADDR);/*设置多播IP地址*/ mcast_addr.sin_port = htons(MCAST_PORT); /*设置多播端口*/ #if 0 err = bind(s,(struct sockaddr*)&mcast_addr, sizeof(mcast_addr)) ; if(err < 0) { perror("bind()"); return -2; } #endif int n; int count = 3; /*向多播地址发送数据*/ do { n = sendto(s, /*套接字描述符*/ &hello, /*数据*/ sizeof(hello), /*长度*/ 0, (struct sockaddr*)&mcast_addr, sizeof(mcast_addr)) ; if( n < 0) { ut_err("sendto() fail errno:%d\n", errno); } count--; sleep(MCAST_INTERVAL); /*等待一段时间*/ }while(-1 == n && count > 0); close(s); return 0; }
int main(int argc,char** argv) { char _path[260]; char _root[260]; FiEvent evnt; INIT_G(); G.logFileSize = _M(100); G.logFile.fd = STDOUT_FILENO; FiGetCurDir(sizeof(_path),_path); strcpy(_root, _path); std::string str(_path); dirname(_root); append_slash(_root); G.exe = _path; G.root = _root; str+="FiUpdateMgr.log"; freopen(str.c_str(),"a",stdout); #if 1 if (0 == chdir(G.exe)) { ut_dbg("change cur dir success\n"); } else { ut_err("change cur dir fail\n"); } #endif #ifndef WIN32 FiEnableCoreDumps(); pthread_t tid[3]; pthread_attr_t attr[3]; struct stat st; umparams.type = SERVER;//default type umparams.master == false; FiUpdateAssistant::getinstance()->set(&evnt); if (init_param(argc, argv) < 0) { print_usage(stderr, 1); return -1; } if (stat("../download", &st) == -1) { ut_err("stat error num :%d\n", errno); } else { if (!S_ISDIR(st.st_mode)) { system("rm ../download -rf"); } } system("mkdir -p ../download"); if (pthread_attr_init(&attr[0]) < 0) { ut_err("set attr fail\n"); } if (pthread_attr_init(&attr[1]) < 0) { ut_err("set attr fail\n"); } if (pthread_attr_init(&attr[2]) < 0) { ut_err("set attr fail\n"); } pthread_attr_setdetachstate(&attr[0], PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr[1], PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr[2], PTHREAD_CREATE_DETACHED); if (sendHello()<0) { ut_err("send hello fail\n"); } pthread_create(&tid[0], &attr[0], selfUpdate, NULL); if (umparams.master == false) { pthread_create(&tid[1], &attr[1], recvHelloHandler, NULL); } else { pthread_create(&tid[2], &attr[2], heartHandler, NULL); } #endif UpdateSrv = new FiRpcSrv<FiUpdateMgrImpl>(RPC_PORT, RPC_SERVER_NAME, (char*)(NULL)); UpdateSrv->run(); #if 0 evnt.wait(); #else do { #ifdef WIN32 Sleep(1000); #else sleep(1); #endif }while(true); #endif return 0; }
/** * @brief 根据客户端的版本信息,返回客户端需要的版本 集合(链表) * * @param version * @param patchs * * @return */ ::CORBA::Long FiUpdateMgrImpl::queryPatchs(const char* version, ::patchSet_t patchs) { //version: cur ver fics_v1.0.0_2015.10.16_4005 //paths cur pat num set //need to set value patshs // long patchs[100]; int patch = 0;//读取patch_version文件 4005 int baseVer = 0; int patchVer = 0; int i=0; char fileNameRE[512]={0};//Regular Expression version_t curVer; int tmpVer = 0; char cmdBuf[512]; char tmppath[256]={0}; char *pos; char *date; char *fileName; FILE *fp = NULL; int r=0; /*----------------------------------------------------------------------------- * 0. scan fics_v1.0.0_2015.09.12_4000.zip -- fics_v1.0.0_2015.10.16_4005.zip * 1. get base num, get patchNum * 2. scan a *-----------------------------------------------------------------------------*/ memset(patchs, 0 ,sizeof(patchSet_t));//客户端 全为0 传过来就不为0 if (getLocalVersion(&curVer) != 0) { ut_err("get local ver fail\n"); return 1; } patch = atoi(curVer.patchNo); baseVer = getCurBaseVer(patch);//40 patchVer = getCurPatchVer(patch);//5 tmpVer = baseVer * BASEINTERVAL; for (i = 0; i<=patchVer; i++) { sprintf(fileNameRE, "fics_%s_*_%d.zip", curVer.version, tmpVer+i);//reg skip date eg:fics_v1.0.0_*_4005.zip sprintf(cmdBuf, "find %s -name \'%s\'", _PATH_PKG_DL, fileNameRE); if (NULL == (fp = popen(cmdBuf, "r"))) { ut_err("popen error[%d]\n", errno); return 2; } r = fscanf(fp, "%[^\n]s", tmppath); fgetc(fp); if (r == 1) { if (!(fileName = basename(tmppath))) { pclose(fp); continue; } if (!(pos = strstr(fileName, curVer.version))) { pclose(fp); continue; } if (!(pos = strchr(pos, '_'))) { pclose(fp); continue; } date = pos + 1; if (!(pos = strchr(date, '_'))) { pclose(fp); continue; } *pos = 0; patchs[i][0] = 1; patchs[i][1] = date2Long(date); } pclose(fp); } return 0; }
bool updateLocal(version_t *pver) { PlatformInfoEx info; std::string osmode; struct utsname uts; std::vector<std::string> optinalname; int ret; char *p; char *ver = pver->version; char *date = pver->date; char *patchNo = pver->patchNo; int kind = 0; std::string name; std::string nameTmp; bool exist = false; char fullName[256]={0}; char downPkgDir[256]={0}; version_t hisVer; if (!pver) { ut_err("ver is null\n"); goto err; } memset(&hisVer, 0, sizeof(version_t)); getLastVerFromHis(&hisVer, HISTORY); if (strcmp(hisVer.patchNo, pver->patchNo) != 0) { ver = hisVer.version; date = hisVer.date; patchNo = hisVer.patchNo; } uname(&uts); //info.OSRunMode = sizeof(long)*8; p =strstr(uts.release,".");//2.6.38-8-generic,we need only 2.6 if( p!= NULL ) { ++p; p =strstr(p,"."); if(p != NULL) { *p=0; info.OSPackName = (const char*)(uts.release); } } if(info.OSPackName.in()==NULL) { info.OSPackName=""; } osmode = uts.machine; if( osmode.find("x86_64") != std::string::npos) { info.OSRunMode = 64; } else { info.OSRunMode = 32; } info.platform = FiUpdateAssistant::ELINUX; info.OSName ="Linux"; ut_dbg("fiupdate loader get config platform:linux %d bit\n",info.OSRunMode); fflush(stdout); //find location. struct stat statBuf; strcpy(fullName, _PATH_PKG_DL); sprintf(fullName+strlen(fullName), "fics_%s_%s_%s", ver, date, patchNo); sprintf(downPkgDir, "%sfics_%s_%s_%s", _PATH_PKG_DL, ver, date, patchNo); if (-1 == lstat(fullName, &statBuf)) { ut_err("does the pkg dir not exist?\n"); goto err; } if (!S_ISDIR(statBuf.st_mode)) { ut_err("pkg is not dir\n"); goto err; } gen_optional_pack_name(info, optinalname); name = "Massvr_"; name += ver; name += "_"; name += date; name += "_"; name += patchNo; nameTmp = name; name += optinalname[0]; for (kind = 0; kind < optinalname.size();kind++) { name = nameTmp + optinalname[kind]; sprintf(fullName, "%s/%s", downPkgDir, name.c_str()); if (FiIsExistFile(fullName)) { exist = true; break; } else { ut_err("tar is not exist[%s] try Compatible version!!\n", fullName); continue; } } if (!exist) { ut_err("all compatible tar is not exist\n"); goto err; } //trans to curDir char cmdBuf[512]; sprintf(cmdBuf, "cp %s " _PATH_PKG_DL "../update/", fullName); FiExecuteShell(cmdBuf); //begin to install // FiUpdateAssistant::getinstance()->setFile(name); // ret = FiUpdateAssistant::getinstance()->svc(); // ut_dbg("install ret[%d]\n", ret); return true; err: return false; }
int getDirList(char const * path, vector<string> & dirList) { #ifdef WIN32 //此结构说明参MSDN; WIN32_FIND_DATA FindFileData; //查找文件的句柄; HANDLE hListFile; char szFullPath[MAX_PATH]; //相对路径; char szFilePath[MAX_PATH]; //构造相对路径; sprintf(szFilePath, "%s\\*", path); //查找第一个文件,获得查找句柄,如果FindFirstFile返回INVALID_HANDLE_VALUE则返回; if((hListFile = FindFirstFile(szFilePath, &FindFileData)) == INVALID_HANDLE_VALUE) { //查找文件错误; return false; } else { do { //过滤.和..; //“.”代表本级目录“..”代表父级目录; if( FindFileData.cFileName[0]==(TCHAR)('.') ) { continue; } std::string filename = FindFileData.cFileName; //构造全路径; sprintf(szFullPath, "%s\\%s", path, FindFileData.cFileName); //如果是文件夹,则递归调用EnmuDirectory函数; if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { dirList.push_back(filename); } }while(FindNextFile(hListFile, &FindFileData)); } //关闭句柄; FindClose(hListFile); #else DIR* dir=NULL; struct dirent* dirlist; struct stat filestat; if( path == NULL) { ut_err("The path is empty!\n"); return -1; } dir = opendir(path); if( dir == NULL) { ut_err("Open directory : %s failed errno:%d!\n",path,errno); return -2; } while( (dirlist=readdir(dir))!= NULL ) { if((dirlist->d_name[0]=='.')) { continue; } std::string filename =dirlist->d_name; std::string fullName=path; fullName += "/"; fullName += dirlist->d_name; stat(fullName.c_str(),&filestat); if(S_ISDIR(filestat.st_mode) ) { // filename +="/*"; dirList.push_back(filename); } } closedir(dir); #endif return 0; }