예제 #1
0
파일: FilePath.cpp 프로젝트: 8l/oovcde
size_t FilePathGetPosRightPathSep(OovStringRef const path, size_t pos, eReturnPosition rp)
{
    if(FilePathIsPathSep(path, pos) && pos < path.numBytes())
        pos++;
    pos = findPathSep(path, pos);
    if(pos == std::string::npos)
    {
        if(rp == RP_RetPosNatural)
        {
            pos = FilePathGetPosEndDir(path);
        }
    }
    return pos;
}
예제 #2
0
OovStatusReturn FileEnsurePathExists(OovStringRef const path)
    {
    OovStatus status(true, SC_File);
    FilePath fullPath(path, FP_Dir);
    FilePath existingPath = fullPath;

    if(fullPath.find('~') == std::string::npos)
        {
        // Walk up the tree to find a base that exists.
        size_t pos = existingPath.getPosEndDir();
        while(pos != 0 && pos != std::string::npos)
            {
            existingPath.discardTail(pos);
            OovStatus ignoredStatus(true, SC_File);
            if(existingPath.isDirOnDisk(ignoredStatus))
                break;
            else
                pos = existingPath.getPosLeftPathSep(pos, RP_RetPosFailure);
            }
        if(pos == std::string::npos)
            {
            pos = 0;
            }
        while(pos != std::string::npos && status.ok())
            {
            pos = findPathSep(fullPath, pos);
            if(pos != std::string::npos)
                {
                OovString partPathStr = fullPath;
                partPathStr.resize(pos);
                if(!FileIsDirOnDisk(partPathStr, status))
                    {
                    status = FileMakeSubDir(partPathStr);
                    }
                pos++;
                }
            }
        }
    else
        {
        status.set(false, SC_Logic);
        }
    return status;
    }
예제 #3
0
파일: FilePath.cpp 프로젝트: 8l/oovcde
OovString FilePathGetSegment(OovStringRef const path, size_t pos)
{
    OovString part;
    size_t startPos = 0;
    if(FilePathIsPathSep(path, pos))
        startPos = pos+1;
    else
    {
        startPos = rfindPathSep(path, pos);
        if(startPos != std::string::npos)
            startPos++;
        else
            startPos=0;
    }
    size_t endPos = findPathSep(path, startPos);
    if(endPos != std::string::npos)
    {
        --endPos;
        part = std::string(path).substr(startPos, endPos-startPos+1);
    }
    return part;
}
예제 #4
0
파일: FilePath.cpp 프로젝트: 8l/oovcde
bool FileEnsurePathExists(OovStringRef const path)
{
    bool success = true;

    // Walk up the tree to find a base that exists.
    FilePath fp(path, FP_File);
    size_t pos = fp.getPosEndDir();
    while(pos != 0)
    {
        fp.discardTail(pos);
        bool ignoredSuccess = true;
        if(fp.isDirOnDisk(ignoredSuccess))
            break;
        else
            pos = fp.getPosLeftPathSep(pos, RP_RetPosFailure);
    }
    while(pos != std::string::npos && pos != 0 && success)
    {
        pos = findPathSep(path, pos);
        if(pos != std::string::npos)
        {
            OovString partPath = path;
            partPath.resize(pos);
            if(!FileIsDirOnDisk(partPath, success))
            {
#ifdef __linux__
                success = (mkdir(partPath.getStr(), 0x1FF) == 0);       // 0777
#else
                success = (_mkdir(partPath.getStr()) == 0);
#endif
            }
            pos++;
        }
    }
    return success;
}