/** IsExists 가 File/Direcotry에 대해 정상 동작하는지 검사. * */ TEST_FIXTURE(FileFixture, IsExists) { CHECK_EQUAL(0, IsExists(validDirectory)); CHECK_EQUAL(1, IsExists(validFile)); CHECK_EQUAL(0, IsExists(invalidDirectory)); CHECK_EQUAL(0, IsExists(invalidFile)); }
bool CGitExtensionsShellEx::ValidWorkingDir(const std::wstring& dir) { if (dir.empty()) return false; if (IsExists(dir + L"\\.git\\") || IsExists(dir + L"\\.git")) return true; return IsExists(dir + L"\\info\\") && IsExists(dir + L"\\objects\\") && IsExists(dir + L"\\refs\\"); }
bool vfsDirBase::Open(const wxString& path) { if(!IsOpened()) Close(); if(!IsExists(path)) return false; m_cwd += '/' + path; return true; }
void TelnetOptionList::Enable(byte opt) { if (!IsExists(opt)) return; if ((opt == OPT_NEW_ENVIRON) ||(opt == OPT_OLD_ENVIRON)) { Find(OPT_NEW_ENVIRON)->setEnable(true); Find(OPT_OLD_ENVIRON)->setEnable(true); return; } Find(opt)->setEnable(true); }
/** * @brief complete create the directory * * @author hankejia * @date 2012-07-05 * @param[in] pstrRecPath dir is path. * @return T_S32 * @retval if return 0 success, otherwise failed */ T_S32 CompleteCreateDirectory( T_pSTR pstrRecPath ) { T_S32 iRet = 0; T_CHR *pstrTemp = NULL, *pszBackSlash = NULL; assert( pstrRecPath != NULL ); T_pSTR pstrPath = (T_pSTR)malloc( ( strlen( pstrRecPath ) + 1 ) ); if ( NULL == pstrRecPath ) { loge( "CompleteCreateDirectory::Out of memory!\n" ); return -1; } strcpy( pstrPath, pstrRecPath ); pstrTemp = strchr( pstrPath, '/' ); while( 1 ) { pszBackSlash = strchr( pstrTemp + 1, '/' ); if ( NULL == pszBackSlash ) break; *pszBackSlash= '\0'; if ( IsExists( pstrPath ) ) { *pszBackSlash = '/'; pstrTemp = pszBackSlash; continue; } if ( mkdir( pstrPath, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 ) { loge( "CompleteCreateDirectory::can't create dir %s, error = %s", pstrPath, strerror(errno) ); iRet = -1; goto Exit; } *pszBackSlash = '/'; pstrTemp = pszBackSlash; } if ( ( mkdir( pstrPath, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 ) && ( errno != EEXIST ) ) { loge( "CompleteCreateDirectory::can't complete create dir %s! error = %s!\n", pstrPath, strerror(errno) ); iRet = -1; } Exit: free( pstrPath ); return iRet; }
static T_pSTR MakeFileName( ) { //T_U32 nSuffizeIndex = 0, nFileIndex = 0, nLastLen = 0; T_U32 nFileIndex = 0; //T_pSTR strTime = NULL; T_pSTR strFileName = NULL; //T_pSTR strNumer = NULL; char name[20]; char file[20]; char num[5]; struct tm *tnow = GetCurTime(); //assert( handle ); //strTime = GetCurTimeStr(); memset(name, 0x00, 20); sprintf( name, "/mnt/DC%4d%02d%02d/", 1900 + tnow->tm_year, tnow->tm_mon + 1, tnow->tm_mday ); CompleteCreateDirectory(name); memset(file, 0x00, 20); sprintf(file, "DC%02d%02d%02d", tnow->tm_hour, tnow->tm_min, tnow->tm_sec); { strFileName = (T_pSTR)malloc( strlen(file) + 30 ); if ( NULL == strFileName ) { goto err; } memset(strFileName, 0x00, strlen(file) + 30); strcat(strFileName, name); strcat( strFileName, file ); strcat( strFileName, ".jpeg" ); //free( strTime ); //strTime = NULL; } while ( AK_TRUE ) { if ( IsExists( strFileName ) ) { ++nFileIndex; if ( nFileIndex > 99 ) { printf( "MakeFileName::too many file have same name!\n" ); goto err; } memset(strFileName, 0x00, strlen(file) + 30); sprintf(num, "_%02d", ( int )nFileIndex); strcat(strFileName, name); strcat( strFileName, file ); strcat(strFileName, num); strcat( strFileName, ".jpeg" ); //strNumer = strFileName + nLastLen; //sprintf( strNumer, "(%02d)", (int)(nFileIndex++) ); continue; } break; } return strFileName; err: /* if ( strTime ) { free( strTime ); } */ if ( strFileName ) { free( strFileName ); strFileName = NULL; } return strFileName; }
bool TelnetOptionList::IsEnabled(byte opt) { return (IsExists(opt)) ? Find(opt)->getEnable() : false; }
void TelnetOptionList::SetRequested(byte opt, bool state) { if (!IsExists(opt)) return; Find(opt)->setRequested(state); }
bool TelnetOptionList::IsRequestInit(byte opt) { return (IsExists(opt)) ? Find(opt)->getRequestInit() : false; }
void TelnetOptionList::Add(byte opt, bool requestInit) { if (IsExists(opt)) return; m_list.push_back(TelnetOpt(opt, requestInit)); }
int cmdRestore(CLISESSION *pSession, int argc, char **argv, void *pHandler) { WORKSESSION *pWorker; char szCommand[128]; int pid, child, status; if (pSession->nType == CLITYPE_TELNET) { OUTTEXT(pSession, "Restore does not support telnet mode.\r\n"); return CLIERR_OK; } if (!Confirm(pSession, MSG_DEFAULT)) return CLIERR_OK; unlink(SAVE_FILENAME); pid = Spawn(child, 1, "/tmp"); if (pid > 0) { if (pSession->nType == CLITYPE_TELNET) { pWorker = (WORKSESSION *)pSession->pSession; dup2(pWorker->sSocket, STDIN_FILENO); dup2(pWorker->sSocket, STDOUT_FILENO); dup2(pWorker->sSocket, STDERR_FILENO); } execl("/usr/bin/rz", "rz", "-b", "-Z", "-y", NULL); exit(0); } while(waitpid(child, &status, WNOHANG) == 0) usleep(1000000); if (!IsExists(SAVE_FILENAME)) { printf("\r\n**** Configration file not found: %s ****\r\n", SAVE_FILENAME); return IF4ERR_INVALID_FILENAME; } usleep(1000000); printf("\r\n"); printf("Remove old configuration.\r\n"); VARAPI_EnableModify(FALSE); system("rm -rf /app/conf"); system("rm -rf /app/member"); system("rm -rf /app/data"); system("rm -rf /app/event"); system("rm -rf /app/log"); system("rm -f /app/sw/apn"); system("rm -f /app/sw/phonelist"); printf("Make new configuration.\r\n"); chdir("/app"); sprintf(szCommand, "tar zxvf %s > /tmp/result", SAVE_FILENAME); system(szCommand); system("/bin/chown -R root:root /app/conf"); system("/bin/chown -R root:root /app/sw"); system("/bin/chown -R root:root /app/data"); system("/bin/chown -R root:root /app/log"); unlink(SAVE_FILENAME); chdir("/app/sw"); printf("Sync ...\r\n"); system("sync"); usleep(1000000); system("sync"); usleep(1000000); system("sync"); printf("Reboot.\r\n"); ResetSystem(); return CLIERR_OK; }
int MakeBackupFile(CLISESSION *pSession, const char *pszFileName, int nType) { char szCommand[256]; char szName[64], *p; int pid, child, status; strcpy(szName, pszFileName); p = strstr(szName, ".gz"); if (p != NULL) *p = '\0'; if (IsExists(szName)) unlink(szName); if (IsExists(pszFileName)) unlink(pszFileName); OUTTEXT(pSession, "\r\n"); if ((nType == BACKUP_TYPE_ALL) || (nType == BACKUP_TYPE_CONFIG)) { OUTTEXT(pSession, "Save configuration.\r\n"); VARAPI_Save(TRUE); usleep(1000000); system("sync"); usleep(1000000); system("sync"); } chdir("/app"); OUTTEXT(pSession, "Make compress file.\r\n"); sprintf(szCommand, "tar cf %s", szName); if ((nType == BACKUP_TYPE_ALL) || (nType == BACKUP_TYPE_CONFIG)) { // 환경 파일 strcat(szCommand, " conf member sw/ppp/chatscript sw/ppp/peers"); if (IsExists("/app/sw/phonelist")) strcat(szCommand, " sw/phonelist"); } if (nType == BACKUP_TYPE_ALL) { // 검침 데이터와 로그 strcat(szCommand, " data log"); } strcat(szCommand, " > /tmp/result"); system(szCommand); sprintf(szCommand, "gzip %s > /tmp/result", szName); system(szCommand); chdir("/app/sw"); OUTTEXT(pSession, "Upload file.\r\n"); pid = Spawn(child, 1, "/tmp"); if (pid > 0) { execl("/usr/bin/sz", "sz", pszFileName, NULL); exit(0); } while(waitpid(child, &status, WNOHANG) == 0) usleep(1000000); unlink(pszFileName); return CLIERR_OK; }