Exemple #1
0
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;
}
Exemple #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;
    }
Exemple #3
0
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;
}
Exemple #4
0
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;
}