//++ ------------------------------------------------------------------------------------ // Details: Retrieve the frame information from LLDB frame object. // Type: Method. // Args: vrFrame - (R) LLDB thread object. // vPc - (W) Address number. // vFnName - (W) Function name. // vFileName - (W) File name text. // vPath - (W) Full file name and path text. // vnLine - (W) File line number. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. // Throws: None. //-- bool CMICmnLLDBDebugSessionInfo::GetFrameInfo(const lldb::SBFrame &vrFrame, lldb::addr_t &vwPc, CMIUtilString &vwFnName, CMIUtilString &vwFileName, CMIUtilString &vwPath, MIuint &vwnLine) { lldb::SBFrame &rFrame = const_cast<lldb::SBFrame &>(vrFrame); static char pBuffer[MAX_PATH]; const MIuint nBytes = rFrame.GetLineEntry().GetFileSpec().GetPath(&pBuffer[0], sizeof(pBuffer)); MIunused(nBytes); CMIUtilString strResolvedPath(&pBuffer[0]); const char *pUnkwn = "??"; if (!ResolvePath(pUnkwn, strResolvedPath)) return MIstatus::failure; vwPath = strResolvedPath; vwPc = rFrame.GetPC(); const char *pFnName = rFrame.GetFunctionName(); vwFnName = (pFnName != nullptr) ? pFnName : pUnkwn; const char *pFileName = rFrame.GetLineEntry().GetFileSpec().GetFilename(); vwFileName = (pFileName != nullptr) ? pFileName : pUnkwn; vwnLine = rFrame.GetLineEntry().GetLine(); return MIstatus::success; }
TransactionResult::Enum MarkAsProcessed(const std::string &Path) { std::string Absolute; if (!ResolvePath(Path.c_str(), Absolute)) { DB->ErrorMessage = "could not find file on disk: "; DB->ErrorMessage += Path; return TransactionResult::ERROR; } Statement SQL; TransactionResult::Enum tret = SQL.TxnPrepare(*DB, "SELECT id FROM files " "WHERE path = ? ORDER BY id DESC LIMIT 1"); if (tret != TransactionResult::COMMIT) { return tret; } sqlite3_bind_text(SQL.Ptr, 1, Absolute.data(), Absolute.size(), SQLITE_TRANSIENT); int ret = sqlite3_step(SQL.Ptr); if (ret == SQLITE_DONE) { // File is not in the database. No need to mask older errors. return TransactionResult::COMMIT; } if (ret != SQLITE_ROW) { return DB->SetTransactionError(sqlite3_sql(SQL.Ptr)); } // Add an entry for the file, hiding the previous reports. // TODO: Only hide changed files? What about plugin changes? if (Resolve(Path) == NULL) { return TransactionResult::ERROR; } return TransactionResult::COMMIT; }
CFile::ERRCODE CWinFileSystem::GetCurrentDirectory(CStrAny &sDir) { char *pPath = _getcwd(0, 0); if (!pPath) { sDir.Clear(); return (CFile::ERRCODE) errno; } sDir = ResolvePath(CStrAny(ST_WHOLE, pPath)); free(pPath); return 0; }
initrd_inode_t* ResolvePath(int fd, initrd_superblock_t* sb, initrd_inode_t* inode, const char* path) { if ( !path[0] ) { return CloneInode(inode); } if ( path[0] == '/' ) { if ( !INITRD_S_ISDIR(inode->mode) ) { errno = ENOTDIR; return NULL; } return ResolvePath(fd, sb, inode, path+1); } size_t elemlen = strcspn(path, "/"); char* elem = Substring(path, 0, elemlen); uint32_t ino = Traverse(fd, sb, inode, elem); free(elem); if ( !ino ) { return NULL; } initrd_inode_t* child = GetInode(fd, sb, ino); if ( !child ) { return NULL; } if ( !path[elemlen] ) { return child; } initrd_inode_t* result = ResolvePath(fd, sb, child, path + elemlen); free(child); return result; }
bool JPSPlusPathFinder::Run(const Cell& startCell, const Cell& goalCell, List<const Cell*>* outPath) { if (startCell.Capability()!=0 || goalCell.Capability()!=0) return false; mOpenList.Clear(); mPathNodes.Clear(); PathNode& pathNode = mPathNodes[startCell.Id()]; pathNode.CurrentToGoalCost = HDistance(startCell, goalCell); mOpenList.Push(pathNode.CurrentToGoalCost, &startCell); while (!mOpenList.IsEmpty()) { const Cell* currentCell = mOpenList.Top().Value; if (currentCell == &goalCell) break; mOpenList.Pop(); mPathNodes[currentCell->Id()].IsClosed = 1; if (TraversalNeighbours(currentCell, &goalCell)) { if (outPath!=nullptr) { return ResolvePath(&startCell, &goalCell,*outPath) > 0; } return true; } } if (outPath != nullptr) { ResolvePath(&startCell, &goalCell, *outPath); } return true; }
FileIdentification::FileIdentification(const char *path) : Mtime(0), Size(0) { if (ResolvePath(path, Path)) { struct stat st; int ret = lstat(Path.c_str(), &st); if (ret == 0) { Mtime = st.st_mtime; Size = st.st_size; } else { Path.clear(); } } }
//++ ------------------------------------------------------------------------------------ // Details: Return the resolved file's path for the given file. // Type: Method. // Args: vCmdData - (R) A command's information. // vPath - (R) Original path. // vwrResolvedPath - (W) Resolved path. // Return: MIstatus::success - Functional succeeded. // MIstatus::failure - Functional failed. // Throws: None. //-- bool CMICmnLLDBDebugSessionInfo::ResolvePath( const SMICmdData & vCmdData, const CMIUtilString & vPath, CMIUtilString & vwrResolvedPath ) { // ToDo: Verify this code as it does not work as vPath is always empty CMIUtilString strResolvedPath; if( !SharedDataRetrieve( "Working Directory", strResolvedPath ) ) { vwrResolvedPath = ""; SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ERR_SHARED_DATA_NOT_FOUND ), vCmdData.strMiCmd.c_str(), "Working Directory" ) ); return MIstatus::failure; } vwrResolvedPath = vPath; return ResolvePath( strResolvedPath, vwrResolvedPath ); }
const TreeNode *TreeNode::Child(const std::string& s) const { std::string name; const TreeNode *parent = ResolvePath(s, name); Children::const_iterator it(mChildren.begin()), itEnd(mChildren.end()); for(; it!=itEnd; ++it) { TreeNode *child = *it; if (!child->mbIsText) { if (child->mName == "lina:data") { const TreeNode *t = child->Child(name); if (t) return t; } if (child->mName == name) return *it; } } return NULL; }
void scandir(const std::string& path, const std::string& extension, std::vector<std::string>* files) { files->clear(); std::string search_path = path.empty() ? "." : path; DIR* dir = opendir(ResolvePath(search_path).c_str()); if (!dir) return; struct dirent entry; struct dirent* result; while (readdir_r(dir, &entry, &result) == 0) { if (result == NULL) break; if (mats::ends_with(entry.d_name, extension)) { files->emplace_back(entry.d_name); } } closedir(dir); }
/* Resolves actor paths a la LoadActor("..."), with autowildcarding and .redir * files. Returns a path *within* the Rage filesystem, unlike the FILEMAN * function of the same name. */ bool ActorUtil::ResolvePath( RString &sPath, const RString &sName, bool optional ) { CollapsePath( sPath ); // If we know this is an exact match, don't bother with the GetDirListing, // so "foo" doesn't partial match "foobar" if "foo" exists. RageFileManager::FileType ft = FILEMAN->GetFileType( sPath ); if( ft != RageFileManager::TYPE_FILE && ft != RageFileManager::TYPE_DIR ) { vector<RString> asPaths; GetDirListing( sPath + "*", asPaths, false, true ); // return path too if( asPaths.empty() ) { if(optional) { return false; } RString sError = ssprintf( "%s: references a file \"%s\" which doesn't exist", sName.c_str(), sPath.c_str() ); switch(LuaHelpers::ReportScriptError(sError, "BROKEN_FILE_REFERENCE", true)) { case Dialog::abort: RageException::Throw( "%s", sError.c_str() ); break; case Dialog::retry: FILEMAN->FlushDirCache(); return ResolvePath( sPath, sName ); case Dialog::ignore: return false; default: FAIL_M("Invalid response to Abort/Retry/Ignore dialog"); } } THEME->FilterFileLanguages( asPaths ); if( asPaths.size() > 1 ) { RString sError = ssprintf( "%s: references a file \"%s\" which has multiple matches", sName.c_str(), sPath.c_str() ); sError += "\n" + join( "\n", asPaths ); switch(LuaHelpers::ReportScriptError(sError, "BROKEN_FILE_REFERENCE", true)) { case Dialog::abort: RageException::Throw( "%s", sError.c_str() ); break; case Dialog::retry: FILEMAN->FlushDirCache(); return ResolvePath( sPath, sName ); case Dialog::ignore: asPaths.erase( asPaths.begin()+1, asPaths.end() ); break; default: FAIL_M("Invalid response to Abort/Retry/Ignore dialog"); } } sPath = asPaths[0]; } if( ft == RageFileManager::TYPE_DIR ) { RString sLuaPath = sPath + "/default.lua"; if( DoesFileExist(sLuaPath) ) { sPath = sLuaPath; return true; } } sPath = DerefRedir( sPath ); return true; }
Actor *ActorUtil::LoadFromNode( const XNode* _pNode, Actor *pParentActor ) { ASSERT( _pNode != NULL ); XNode node = *_pNode; // Remove this in favor of using conditionals in Lua. -Chris // There are a number of themes out there that depend on this (including // sm-ssc default). Probably for the best to leave this in. -aj { bool bCond; if( node.GetAttrValue("Condition", bCond) && !bCond ) return NULL; } RString sClass; bool bHasClass = node.GetAttrValue( "Class", sClass ); if( !bHasClass ) bHasClass = node.GetAttrValue( "Type", sClass ); bool bLegacy = (node.GetAttr( "_LegacyXml" ) != NULL); if( !bHasClass && bLegacy ) sClass = GetLegacyActorClass( &node ); map<RString,CreateActorFn>::iterator iter = g_pmapRegistrees->find( sClass ); if( iter == g_pmapRegistrees->end() ) { RString sFile; if (bLegacy && node.GetAttrValue("File", sFile) && sFile != "") { RString sPath; // Handle absolute paths correctly if (sFile.Left(1) == "/") sPath = sFile; else sPath = Dirname(GetSourcePath(&node)) + sFile; if (ResolvePath(sPath, GetWhere(&node))) { Actor *pNewActor = MakeActor(sPath, pParentActor); if (pNewActor == NULL) return NULL; if (pParentActor) pNewActor->SetParent(pParentActor); pNewActor->LoadFromNode(&node); return pNewActor; } } // sClass is invalid RString sError = ssprintf( "%s: invalid Class \"%s\"", ActorUtil::GetWhere(&node).c_str(), sClass.c_str() ); LuaHelpers::ReportScriptError(sError); return new Actor; // Return a dummy object so that we don't crash in AutoActor later. } const CreateActorFn &pfn = iter->second; Actor *pRet = pfn(); if( pParentActor ) pRet->SetParent( pParentActor ); pRet->LoadFromNode( &node ); return pRet; }
void CommandPromptProcess(ScriptValue &s, ScriptValue* args) { if (0) { char buf[1024]; //i/o buffer STARTUPINFOA si; SECURITY_ATTRIBUTES sa; PROCESS_INFORMATION pi; HANDLE newstdin,newstdout,read_stdout,write_stdin; //pipe handles sa.lpSecurityDescriptor = NULL; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle = true; //allow inheritable handles if (!CreatePipe(&newstdin,&write_stdin,&sa,0)) //create stdin pipe { return; } if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) //create stdout pipe { CloseHandle(newstdin); CloseHandle(write_stdin); return; } GetStartupInfoA(&si); //set startupinfo for the spawned process /* The dwFlags member tells CreateProcess how to make the process. STARTF_USESTDHANDLES validates the hStd* members. STARTF_USESHOWWINDOW validates the wShowWindow member. */ si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; si.hStdOutput = newstdout; si.hStdError = newstdout; //set the new handles for the child process si.hStdInput = newstdin; char app_spawn[] = "C:\\windows\\system32\\ping.exe"; //sample, modify for your //system //spawn the child process if (!CreateProcessA(app_spawn,NULL,NULL,NULL,TRUE,CREATE_NEW_CONSOLE, NULL,NULL,&si,&pi)) { CloseHandle(newstdin); CloseHandle(newstdout); CloseHandle(read_stdout); CloseHandle(write_stdin); return; } unsigned long exit=0; //process exit code unsigned long bread; //bytes read unsigned long avail; //bytes available for(;;) //main program loop { PeekNamedPipe(read_stdout,buf,1023,&bread,&avail,NULL); //check to see if there is any data to read from stdout if (bread != 0) { if (avail > 1023) { while (bread >= 1023) { ReadFile(read_stdout,buf,1023,&bread,NULL); //read the stdout pipe printf("%s",buf); } } else { ReadFile(read_stdout,buf,1023,&bread,NULL); printf("%s",buf); } } GetExitCodeProcess(pi.hProcess,&exit); //while the process is running if (exit != STILL_ACTIVE) break; /* if (kbhit()) //check for user input. { bzero(buf); *buf = (char)getche(); //printf("%c",*buf); WriteFile(write_stdin,buf,1,&bread,NULL); //send it to stdin if (*buf == '\r') { *buf = '\n'; printf("%c",*buf); WriteFile(write_stdin,buf,1,&bread,NULL); //send an extra newline char, //if necessary } } //*/ } CloseHandle(pi.hThread); CloseHandle(pi.hProcess); CloseHandle(newstdin); //clean stuff up CloseHandle(newstdout); CloseHandle(read_stdout); CloseHandle(write_stdin); } wchar_t *path = ResolvePath(args[0].stringVal->value); wchar_t *dir = 0; if (path && (!args[2].stringVal->len || (dir = ResolvePath(args[2].stringVal->value)))) { STARTUPINFO si; PROCESS_INFORMATION pi; memset(&si, 0, sizeof(si)); si.cb = sizeof(si); wchar_t *params = UTF8toUTF16Alloc(args[1].stringVal->value); ConnectedProcess *cp = 0; cp = (ConnectedProcess*)calloc(1,sizeof(ConnectedProcess)); if (cp) { SECURITY_ATTRIBUTES saAttr; saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = NULL; static __int64 namedPipes = 0; char pipeNames[3][100]; sprintf(pipeNames[0], "\\\\.\\pipe\\LCD Miscellany error pipe %I64i", namedPipes); sprintf(pipeNames[1], "\\\\.\\pipe\\LCD Miscellany out pipe %I64i", namedPipes); sprintf(pipeNames[2], "\\\\.\\pipe\\LCD Miscellany in pipe %I64i", namedPipes); namedPipes++; //* cp->error[0] = CreateNamedPipeA(pipeNames[0], PIPE_ACCESS_INBOUND, PIPE_TYPE_BYTE | PIPE_WAIT, 1, 1024, 1024, 5000, 0); cp->error[1] = CreateFileA(pipeNames[0], GENERIC_WRITE, 0, &saAttr, OPEN_EXISTING, 0, 0); cp->out[0] = CreateNamedPipeA(pipeNames[1], PIPE_ACCESS_INBOUND, PIPE_TYPE_BYTE | PIPE_WAIT, 1, 1024, 1024, 5000, 0); cp->out[1] = CreateFileA(pipeNames[1], GENERIC_WRITE, 0, &saAttr, OPEN_EXISTING, 0, 0); cp->in[0] = CreateNamedPipeA(pipeNames[2], PIPE_ACCESS_OUTBOUND, PIPE_TYPE_BYTE | PIPE_WAIT, 1, 1024, 1024, 5000, 0); cp->in[1] = CreateFileA(pipeNames[2], GENERIC_READ, 0, &saAttr, OPEN_EXISTING, 0, 0); //*/ //CreatePipe(&cp->error[0], &cp->error[1], &saAttr, 0); //CreatePipe(&cp->out[0], &cp->out[1], &saAttr, 0); //CreatePipe(&cp->in[1], &cp->in[0], &saAttr, 0); int happy = 1; for (int i=0; i<3; i++) { if (cp->handles[2*i] == INVALID_HANDLE_VALUE || cp->handles[2*i+1] == INVALID_HANDLE_VALUE) { happy = 0; } } if (happy) { si.hStdError = cp->out[1]; si.hStdInput = cp->in[1]; si.hStdOutput = cp->out[1]; si.dwFlags = STARTF_USESTDHANDLES; if (!CreateProcessW(L"c:\\Windows\\System32\\PING.EXE", 0, 0, 0, 1, CREATE_NEW_CONSOLE, 0, dir, &si, &pi)/* && CreateListValue(s, 4)//*/) { happy = 0; } else { CreateIntValue(s, pi.dwProcessId); if (si.dwFlags) { char temp[1000]; { DWORD bread, avail; //PeekNamedPipe(read_stdout,temp,1000,&bread,&avail,NULL); PeekNamedPipe(cp->out[0],temp,1000,&bread,&avail,NULL); PeekNamedPipe(cp->in[0],temp,1000,&bread,&avail,NULL); bread = bread; } DWORD read = 0; ReadFile(cp->out[0], temp, 1, &read, 0); ReadFile(cp->error[0], temp, 1, &read, 0); ReadFile(cp->in[0], temp, 1000, &read, 0); read = read; } } } if (!happy) { if (cp) { for (int i=0; i<6; i++) { if (cp->handles[i] != INVALID_HANDLE_VALUE) { CloseHandle(cp->handles[i]); } } free(cp); } } } free(params); } free(path); free(dir); }
Stroka ResolvePath(const char* path, bool isDir) { char buf[PATH_MAX]; if (ResolvePath(path, NULL, buf, isDir)) ythrow yexception() << "cannot resolve path: \"" << path << "\""; return buf; }
std::string GlobalConfigData::ResolveTmpDataPath() { return ResolvePath(TmpDataPath); }
std::string GlobalConfigData::ResolveHTTPCARPath() { return ResolvePath(HTTPCARFolder); }
void DirectFilenameDB::PopulateFileSet( FileSet &fs, const RString &path ) { RString sPath = path; #if defined(XBOX) /* Xbox doesn't handle path names which end with ".", which are used when using an * alternative song directory */ if( sPath.size() > 0 && sPath.Right(1) == "." ) sPath.erase( sPath.size() - 1 ); #endif /* Resolve path cases (path/Path -> PATH/path). */ ResolvePath( sPath ); fs.age.GetDeltaTime(); /* reset */ fs.files.clear(); #if defined(WIN32) WIN32_FIND_DATA fd; if ( sPath.size() > 0 && sPath.Right(1) == "/" ) sPath.erase( sPath.size() - 1 ); HANDLE hFind = DoFindFirstFile( root+sPath+"/*", &fd ); CHECKPOINT_M( root+sPath+"/*" ); if( hFind == INVALID_HANDLE_VALUE ) return; do { if( !strcmp(fd.cFileName, ".") || !strcmp(fd.cFileName, "..") ) continue; File f; f.SetName( fd.cFileName ); f.dir = !!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); f.size = fd.nFileSizeLow; f.hash = fd.ftLastWriteTime.dwLowDateTime; fs.files.insert( f ); } while( FindNextFile( hFind, &fd ) ); FindClose( hFind ); #else /* Ugly: POSIX threads are not guaranteed to have per-thread cwds, and only * a few systems have openat() or equivalent; one or the other is needed * to do efficient, thread-safe directory traversal. Instead, we have to * use absolute paths, which forces the system to re-parse the directory * for each file. This isn't a major issue, since most large directory * scans are I/O-bound. */ DIR *pDir = opendir(root+sPath); if( pDir == NULL ) return; while( struct dirent *pEnt = readdir(pDir) ) { if( !strcmp(pEnt->d_name, ".") ) continue; if( !strcmp(pEnt->d_name, "..") ) continue; File f( pEnt->d_name ); struct stat st; if( DoStat(root+sPath + "/" + pEnt->d_name, &st) == -1 ) { int iError = errno; /* If it's a broken symlink, ignore it. Otherwise, warn. */ if( lstat(root+sPath + "/" + pEnt->d_name, &st) == 0 ) continue; /* Huh? */ WARN( ssprintf("Got file '%s' in '%s' from list, but can't stat? (%s)", pEnt->d_name, sPath.c_str(), strerror(iError)) ); continue; } else { f.dir = (st.st_mode & S_IFDIR); f.size = (int)st.st_size; f.hash = st.st_mtime; } fs.files.insert(f); } closedir( pDir ); #endif /* * Check for any ".ignore" markers. If a marker exists, hide the marker and its * corresponding file. * For example, if "file.xml.ignore" exists, hide both it and "file.xml" by * removing them from the file set. * Ignore markers are used for convenience during build staging and are not used in * performance-critical situations. To avoid incurring some of the overheard * due to ignore markers, delete the file instead instead of using an ignore marker. */ static const RString IGNORE_MARKER_BEGINNING = "ignore-"; vector<RString> vsFilesToRemove; for( set<File>::iterator iter = fs.files.lower_bound(IGNORE_MARKER_BEGINNING); iter != fs.files.end(); ++iter ) { if( !BeginsWith( iter->lname, IGNORE_MARKER_BEGINNING ) ) break; RString sFileLNameToIgnore = iter->lname.Right( iter->lname.length() - IGNORE_MARKER_BEGINNING.length() ); vsFilesToRemove.push_back( iter->name ); vsFilesToRemove.push_back( sFileLNameToIgnore ); } FOREACH_CONST( RString, vsFilesToRemove, iter ) { // Erase the file corresponding to the ignore marker File fileToDelete; fileToDelete.SetName( *iter ); set<File>::iterator iter2 = fs.files.find( fileToDelete ); if( iter2 != fs.files.end() ) fs.files.erase( iter2 ); }
int main(int argc, char* argv[]) { bool all = false; const char* argv0 = argv[0]; for ( int i = 1; i < argc; i++ ) { const char* arg = argv[i]; if ( arg[0] != '-' || !arg[1] ) continue; argv[i] = NULL; if ( !strcmp(arg, "--") ) break; if ( arg[1] != '-' ) { char c; while ( (c = *++arg) ) switch ( c ) { default: fprintf(stderr, "%s: unknown option -- '%c'\n", argv0, c); help(stderr, argv0); exit(1); } } else if ( !strcmp(arg, "--help") ) help(stdout, argv0), exit(0); else if ( !strcmp(arg, "--version") ) version(stdout, argv0), exit(0); else if ( !strcmp(arg, "-a") ) all = true; else { fprintf(stderr, "%s: unknown option: %s\n", argv0, arg); help(stderr, argv0); exit(1); } } compact_arguments(&argc, &argv); if ( argc == 1 ) error(1, 0, "No initrd specified"); const char* initrd = argv[1]; if ( argc == 2 ) error(1, 0, "No command specified"); const char* cmd = argv[2]; if ( argc == 3 ) error(1, 0, "No path specified"); const char* path = argv[3]; int fd = open(initrd, O_RDONLY); if ( fd < 0 ) { error(1, errno, "open: %s", initrd); } initrd_superblock_t* sb = GetSuperBlock(fd); if ( !sb ) { error(1, errno, "read: %s", initrd); } if ( path[0] != '/' ) { error(1, ENOENT, "%s", path); } initrd_inode_t* root = GetInode(fd, sb, sb->root); if ( !root ) { error(1, errno, "read: %s", initrd); } initrd_inode_t* inode = ResolvePath(fd, sb, root, path+1); if ( !inode ) { error(1, errno, "%s", path); } free(root); if ( !strcmp(cmd, "cat") ) { if ( !PrintFile(fd, sb, inode) ) { error(1, errno, "%s", path); } } else if ( !strcmp(cmd, "ls") ) { initrd_inode_t* dir = inode; if ( !ListDirectory(fd, sb, dir, all) ) { error(1, errno, "%s", path); } } else { fprintf(stderr, "%s: unrecognized command: %s", argv0, cmd); exit(1); } free(inode); free(sb); close(fd); return 0; }
CFile::ERRCODE CWinFileSystem::DeleteFile(CStrAny const &sFile) { CStrAny sPath = ResolvePath(sFile); int iRes = _unlink(sPath.m_pBuf); return (iRes < 0) ? (CFile::ERRCODE) errno : 0; }
CFile::ERRCODE CWinFileSystem::DeleteDirectory(CStrAny const &sDir) { CStrAny sPath = ResolvePath(sDir); int iRes = _rmdir(sPath.m_pBuf); return (iRes < 0) ? (CFile::ERRCODE) errno : 0; }
std::string GlobalConfigData::ResolveStaticDataPath() { return ResolvePath(StaticDataPath); }
/// \brief /// Resolves all possible ".." in the path. Accepts \ and / /// /// \param szPath /// The actual path to resolve /// /// \return /// A VString containing the resolved path (no more '..' inside the path) /// /// \note /// Internally creates a temp buffer on the stack. Do not use it extensively for time critical processes. VBASE_IMPEXP static VString ResolvePath(const char* szPath) { char szBuffer[FS_MAX_PATH]; ResolvePath(szBuffer, szPath); return VString(szBuffer); }
std::string GlobalConfigData::ResolveVariableDataPath() { return ResolvePath(VariableDataPath); }
int MakeTempDir(char path[/*FILENAME_MAX*/], const char* prefix) { int ret; Stroka sysTmp; #ifdef _win32_ if (!prefix || *prefix == '/') { #else if (!prefix) { #endif sysTmp = GetSystemTempDir(); prefix = ~sysTmp; } if ((ret = ResolvePath(prefix, NULL, path, 1)) != 0) return ret; if ((ret = isdir(path)) != 0) return ret; if ((strlcat(path, "tmpXXXXXX", FILENAME_MAX) > FILENAME_MAX - 100)) return EINVAL; if (!(mkdtemp(path))) return errno ? errno : EINVAL; strcat(path, LOCSLASH_S); return 0; } int RemoveTempDir(const char* dirName) { DIR *dir; #ifndef DT_DIR struct stat sbp; #endif if ((dir = opendir(dirName)) == 0) return errno ? errno : ENOENT; int ret; dirent ent, *pent; char path[FILENAME_MAX], *ptr; size_t len = strlcpy(path, dirName, FILENAME_MAX); if (path[len-1] != LOCSLASH_C) { path[len] = LOCSLASH_C; path[++len] = 0; } ptr = path + len; while ((ret = readdir_r(dir, &ent, &pent)) == 0 && pent == &ent) { if (!strcmp(ent.d_name, ".") || !strcmp(ent.d_name, "..")) continue; #ifdef DT_DIR if (ent.d_type == DT_DIR) #else lstat(ent.d_name, &sbp); if (S_ISREG(sbp.st_mode)) #endif { ret = ENOTEMPTY; break; } strcpy(ptr, ent.d_name); if (unlink(path)) { ret = errno ? errno : ENOENT; break; } } closedir(dir); if (ret) return ret; *ptr = 0; if (rmdir(path)) return errno ? errno : ENOTEMPTY; return 0; }
std::string GlobalConfigData::ResolveLogPath() { return ResolvePath(LogPath); }
Stroka ResolveDir(const char* path) { return ResolvePath(path, true); }