コード例 #1
0
ファイル: Tree.cpp プロジェクト: flode/ARTSynchronized
    TID Tree::lookup(const Key &k) const {
        N *node = nullptr;
        N *nextNode = root;
        uint32_t level = 0;
        bool optimisticPrefixMatch = false;

        while (true) {
            node = nextNode;
            switch (checkPrefix(node, k, level)) { // increases level
                case CheckPrefixResult::NoMatch:
                    return 0;
                case CheckPrefixResult::OptimisticMatch:
                    optimisticPrefixMatch = true;
                    // fallthrough
                case CheckPrefixResult::Match:
                    if (k.getKeyLen() <= level) {
                        return 0;
                    }
                    nextNode = N::getChild(k[level], node);

                    if (nextNode == nullptr) {
                        return 0;
                    }
                    if (N::isLeaf(nextNode)) {
                        TID tid = N::getLeaf(nextNode);
                        if (level < k.getKeyLen() - 1 || optimisticPrefixMatch) {
                            return checkKey(tid, k);
                        }
                        return tid;
                    }
                    level++;
            }
        }
    }
コード例 #2
0
ファイル: FileMetaDAO.cpp プロジェクト: Thirdhuku/CloudStore
ReturnStatus
FileMetaDAO::isdir(const std::string &path)
{
	Channel* pDataChannel = ChannelManager::getInstance()->Mapping(m_BucketId);
	NameSpace *DataNS = pDataChannel->m_DataNS;

	
    int rt = 0;

	FileAttr st;
    rt = DataNS->Stat(path.c_str(), &st);

    if (0 == rt) {
        if (MU_DIRECTORY == st.m_Type) {
            return ReturnStatus(MU_SUCCESS);

        } else {
            ERROR_LOG("path %s, not directory", path.c_str());
            return ReturnStatus(MU_FAILED, NOT_DIRECTORY);
        }
    }

    int error = errno;

    ERROR_LOG("path %s, stat() error, %s", path.c_str(), strerror(error));

    if (ENOENT == error || ENOTDIR == error) {
        return checkPrefix(path);

    } else {
        return ReturnStatus(MU_FAILED, MU_UNKNOWN_ERROR);
    }
}
コード例 #3
0
bool PrefProxy::rereadPrefs()
{
  ltr_int_free_prefs();
  ltr_int_read_prefs(NULL, true);
  checkPrefix(true);
  return true;
}
コード例 #4
0
ファイル: FileMetaDAO.cpp プロジェクト: Thirdhuku/CloudStore
ReturnStatus
FileMetaDAO::getDir(const std::string &path, std::list<PDEntry> *pEntryList)
{
    assert(pEntryList);

    Channel* pDataChannel = ChannelManager::getInstance()->Mapping(m_BucketId);
	NameSpace *DataNS = pDataChannel->m_DataNS;

    int rt = 0;
    int error = 0;
    std::string entryName;
    Args st;

    rt = DataNS->OpenDir(path.c_str(), &st);

    if (false == st.valid) {
        error = errno;

        ERROR_LOG("path %s, opendir() error, %s.",
                  path.c_str(), strerror(errno));

        if (ENOTDIR == error) {
            return ReturnStatus(MU_FAILED, NOT_DIRECTORY);

        } else if (ENOENT == error) {
            return checkPrefix(path);
        }
    }

    Dirent dirent;

    while(DataNS->ReadDirNext(&st, &dirent)){
        entryName = dirent.filename;

        // omit "." and ".."
        // omit user info file in user root dir
        if (entryName == DENTRY_CURRENT_DIR
            || entryName == DENTRY_PARENT_DIR
            || entryName == USER_INFO_FILE_NAME) {
            continue;
        }

        PDEntry ent;
        ent.m_Name = entryName;

        if (MU_DIRECTORY == dirent.filetype) {
            ent.m_Type = MU_DIRECTORY;

        } else {
            ent.m_Type = MU_REGULAR_FILE;
        }

        pEntryList->push_back(ent);
    }


    return ReturnStatus(MU_SUCCESS);
}
コード例 #5
0
ファイル: Tree.cpp プロジェクト: flode/ARTSynchronized
    void Tree::remove(const Key &k, TID tid) {
        N *node = nullptr;
        N *nextNode = root;
        N *parentNode = nullptr;
        uint8_t parentKey, nodeKey = 0;
        uint32_t level = 0;
        //bool optimisticPrefixMatch = false;

        while (true) {
            parentNode = node;
            parentKey = nodeKey;
            node = nextNode;

            switch (checkPrefix(node, k, level)) { // increases level
                case CheckPrefixResult::NoMatch:
                    return;
                case CheckPrefixResult::OptimisticMatch:
                    // fallthrough
                case CheckPrefixResult::Match: {
                    nodeKey = k[level];
                    nextNode = N::getChild(nodeKey, node);

                    if (nextNode == nullptr) {
                        return;
                    }
                    if (N::isLeaf(nextNode)) {
                        if (N::getLeaf(nextNode) != tid) {
                            return;
                        }
                        assert(parentNode == nullptr || node->getCount() != 1);
                        if (node->getCount() == 2 && node != root) {
                            // 1. check remaining entries
                            N *secondNodeN;
                            uint8_t secondNodeK;
                            std::tie(secondNodeN, secondNodeK) = N::getSecondChild(node, nodeKey);
                            if (N::isLeaf(secondNodeN)) {

                                //N::remove(node, k[level]); not necessary
                                N::change(parentNode, parentKey, secondNodeN);

                                delete node;
                            } else {
                                //N::remove(node, k[level]); not necessary
                                N::change(parentNode, parentKey, secondNodeN);
                                secondNodeN->addPrefixBefore(node, secondNodeK);

                                delete node;
                            }
                        } else {
                            N::removeA(node, k[level], parentNode, parentKey);
                        }
                        return;
                    }
                    level++;
                }
            }
        }
    }
コード例 #6
0
bool findPath(list<Vertex*> &path, const string& word_to_check, int &pathLength){
	Vertex* currV;
	Vertex* nextV;
	stack<Vertex*> adjCad;
	currV=path.back();
	bool found;
	int checkstate;

	if (word_to_check.length() == pathLength){
	    return true;
	}
	else if (word_to_check.length() < pathLength)
		return false;

	//traversal the adj list
	for(int i=0; i < currV->adj.size(); i++){
		if (!currV->adj.at(i)->visited)
			adjCad.push(currV->adj.at(i));
	}

	while (!adjCad.empty()){

		nextV=adjCad.top();
		adjCad.pop();
		checkstate=checkPrefix(path, nextV, word_to_check, pathLength);

		if (checkstate==0) // if the next vertex fails in matching,
			continue;      // go to next availabe candidate in adj of current vertex
		else{
			pathLength+=nextV->name.length();  // if next vertex matches, update vairiables
			path.push_back(nextV);           // push next vertex into path list
			nextV->visited=true;             // indicate next vertex is pushed into the list,
			                                 // not aviable for searching
			if (checkstate==2)          // if the path is found, return true;
				return true;
	        else if (checkstate==1){               // if it is only prefix, recursively searching
				found=findPath(path, word_to_check, pathLength);
				if (found) 
					return true;
				else{                                // if the findPath function false, recover the previous state;
				    pathLength-=nextV->name.length();  // if next vertex matches, update vairiables
			        path.pop_back();                 // push next vertex into path list
			        nextV->visited=false;            // indicate next vertex is pushed into the list,
				}

			}
		}
	}

	return false;
	// if all the vertexs in the adj list all mismatch;
	// this findpath function failed, return false;
}
コード例 #7
0
	virtual State validate(QString &input, int &pos) const
	{
		static const char* p[] = {"o", "frames", "seek", "raw", "hfyu", "slave", NULL};

		bool invalid = checkPrefix(input);

		for(size_t i = 0; p[i] && (!invalid); i++)
		{
			invalid = invalid || checkParam(input, QString::fromLatin1(p[i]), false);
		}
		
		return setStatus(invalid, "Avs2YUV") ? QValidator::Intermediate : QValidator::Acceptable;
	}
コード例 #8
0
	virtual State validate(QString &input, int &pos) const
	{
		static const char* p[] = {"B", "o", "h", "p", "q", /*"fps", "frames",*/ "preset", "tune", "profile",
			"stdin", "crf", "bitrate", "qp", "pass", "stats", "output", "help","quiet", NULL};

		bool invalid = checkPrefix(input);

		for(size_t i = 0; p[i] && (!invalid); i++)
		{
			invalid = invalid || checkParam(input, QString::fromLatin1(p[i]), true);
		}

		return setStatus(invalid, "encoder") ? QValidator::Intermediate : QValidator::Acceptable;
	}
コード例 #9
0
PrefProxy::PrefProxy()
{
  if(ltr_int_read_prefs(NULL, false)){
    checkPrefix(true);
    return;
  }
  ltr_int_log_message("Pref file not found, trying linuxtrack.conf\n");
  if(ltr_int_read_prefs("linuxtrack.conf", false)){
    ltr_int_prefs_changed();
    checkPrefix(true);
    return;
  }
  
  ltr_int_log_message("Couldn't load preferences (GUI), copying default!\n");
  if(!makeRsrcDir()){
    throw;
  }
  if(!copyDefaultPrefs()){
    throw;
  }
  ltr_int_new_prefs();
  ltr_int_read_prefs(NULL, true);
  checkPrefix(true);
}
コード例 #10
0
void FunctionDeclarationCompletionItem::executed(KTextEditor::View* view, const KTextEditor::Range& word)
{
    qCDebug(KDEV_PYTHON_CODECOMPLETION) << "FunctionDeclarationCompletionItem executed";
    KTextEditor::Document* document = view->document();
    auto resolvedDecl = Helper::resolveAliasDeclaration(declaration().data());
    DUChainReadLocker lock;
    auto functionDecl = Helper::functionForCalled(resolvedDecl).declaration;
    lock.unlock();
    if ( ! functionDecl && (! resolvedDecl || ! resolvedDecl->abstractType()
                           || resolvedDecl->abstractType()->whichType() != AbstractType::TypeStructure) ) {
        qCritical(KDEV_PYTHON_CODECOMPLETION) << "ERROR: could not get declaration data, not executing completion item!";
        return;
    }
    QString suffix = "()";
    KTextEditor::Range checkPrefix(word.start().line(), 0, word.start().line(), word.start().column());
    KTextEditor::Range checkSuffix(word.end().line(), word.end().column(), word.end().line(), document->lineLength(word.end().line()));
    if ( m_doNotCall || document->text(checkSuffix).trimmed().startsWith('(')
         || document->text(checkPrefix).trimmed().endsWith('@')
         || (functionDecl && Helper::findDecoratorByName(functionDecl, QLatin1String("property"))) )
    {
        // don't insert brackets if they're already there,
        // the item is a decorator, or if it's an import item.
        suffix.clear();
    }
    // place cursor behind bracktes by default
    int skip = 2;
    if ( functionDecl ) {
        bool needsArguments = false;
        int argumentCount = functionDecl->type<FunctionType>()->arguments().length();
        if ( functionDecl->context()->type() == KDevelop::DUContext::Class ) {
            // it's a member function, so it has the implicit self
            // TODO static methods
            needsArguments = argumentCount > 1;
        }
        else {
            // it's a free function
            needsArguments = argumentCount > 0;
        }
        if ( needsArguments ) {
            // place cursor in brackets if there's parameters
            skip = 1;
        }
    }
    document->replaceText(word, declaration()->identifier().toString() + suffix);
    view->setCursorPosition( Cursor(word.end().line(), word.end().column() + skip) );
}
コード例 #11
0
ファイル: FileMetaDAO.cpp プロジェクト: Thirdhuku/CloudStore
ReturnStatus
FileMetaDAO::statDir(const std::string &path, FileMeta *pMeta)
{
    assert(pMeta);

    Channel* pDataChannel = ChannelManager::getInstance()->Mapping(m_BucketId);
	NameSpace *DataNS = pDataChannel->m_DataNS;

    int rt = 0;
    int error = 0;

	FileAttr st;
	rt = DataNS->Stat(path.c_str(), &st);

    if (-1 == rt) {
        error = errno;
        ERROR_LOG("path %s, stat() error, %s.", path.c_str(), strerror(error));

        if (ENOENT == error || ENOTDIR == error) {
            return checkPrefix(path);

        } else {
            return ReturnStatus(MU_FAILED, MU_UNKNOWN_ERROR);
        }
    }

    if (st.m_Type != MU_DIRECTORY) {
        ERROR_LOG("path %s, not directory", path.c_str());
        return ReturnStatus(MU_FAILED, NOT_DIRECTORY);
    }

    pMeta->m_Attr.m_Mode = st.m_Mode;
    pMeta->m_Attr.m_CTime = st.m_CTime;
    pMeta->m_Attr.m_MTime = st.m_MTime;
    pMeta->m_Attr.m_Size = st.m_Size;

    return ReturnStatus(MU_SUCCESS);
}
コード例 #12
0
ファイル: FileMetaDAO.cpp プロジェクト: Thirdhuku/CloudStore
ReturnStatus
FileMetaDAO::getDir2(const std::string &path,
                     std::list<EDEntry> *pEntryList)
{
    assert(pEntryList);

    Channel* pDataChannel = ChannelManager::getInstance()->Mapping(m_BucketId);
	NameSpace *DataNS = pDataChannel->m_DataNS;

    int rt = 0;
    int error = 0;
    std::string entryName;
    std::string npath;
	Args st;

    rt = DataNS->OpenDir(path.c_str(), &st);
    if (false == st.valid) {
        error = errno;

        ERROR_LOG("path %s, opendir() error, %s.",
                  path.c_str(), strerror(errno));

        if (ENOTDIR == error) {
            return ReturnStatus(MU_FAILED, NOT_DIRECTORY);

        } else if (ENOENT == error) {
            return checkPrefix(path);
        }
    }

    FileMeta meta;
    ReturnStatus rs;
    Dirent dirent;

    while(DataNS->ReadDirNext(&st, &dirent)){
        entryName = dirent.filetype;
        npath = path + PATH_SEPARATOR_STRING + entryName;

        // omit "." and ".."
        // omit user info file in user root dir
        if (entryName == DENTRY_CURRENT_DIR
            || entryName == DENTRY_PARENT_DIR
            || entryName == USER_INFO_FILE_NAME) {
            continue;
        }

        EDEntry ent;
        ent.m_Name = entryName;

        if (MU_DIRECTORY == dirent.filetype) {
            ent.m_Type = MU_DIRECTORY;

            rs = statDir(npath, &meta);

            if (!rs.success()) {
                ERROR_LOG("path %s, statDir() error", npath.c_str());
                return rs;
            }

            ent.m_Mode = meta.m_Attr.m_Mode;
            ent.m_CTime = meta.m_Attr.m_CTime;
            ent.m_MTime = meta.m_Attr.m_MTime;
            ent.m_Size = meta.m_Attr.m_Size;

        } else {
            // clear data of last entry
            meta.m_BlockList.clear();

            rs = getFile(npath, &meta);

            if (!rs.success()) {
                ERROR_LOG("path %s, getFile() error", npath.c_str());
                return rs;
            }

            ent.m_Mode = meta.m_Attr.m_Mode;
            ent.m_CTime = meta.m_Attr.m_CTime;
            ent.m_MTime = meta.m_Attr.m_MTime;
            ent.m_Size = meta.m_Attr.m_Size;
            ent.m_Version = meta.m_Attr.m_Version;
            ent.m_Type = meta.m_Attr.m_Type;

            ent.m_BlockList = meta.m_BlockList;
        }

        pEntryList->push_back(ent);
    }


    return ReturnStatus(MU_SUCCESS);
}
コード例 #13
0
ファイル: FileMetaDAO.cpp プロジェクト: Thirdhuku/CloudStore
ReturnStatus
FileMetaDAO::rmdirRecursive(const std::string &path, uint64_t *pDelta)
{
	Channel* pDataChannel = ChannelManager::getInstance()->Mapping(m_BucketId);
	NameSpace *DataNS = pDataChannel->m_DataNS;
	
    int rt = 0;
    ReturnStatus rs;
    int error = 0;
    std::string entryName;
    std::string npath;
    Args st;

	rt = DataNS->OpenDir(path.c_str(), &st);
    if (rt < 0) {
        error = errno;

        ERROR_LOG("path %s, opendir() error, %s.",
                  path.c_str(), strerror(errno));

        if (ENOTDIR == error) {
            ERROR_LOG("path %s, opendir() error, no directory");
            return ReturnStatus(MU_FAILED, NOT_DIRECTORY);

        } else if (ENOENT == error) {
            return checkPrefix(path);
        }
    }

    // delete its children

    Dirent dirent;

    while(DataNS->ReadDirNext(&st, &dirent)){
        entryName = dirent.filename;

        // omit "." and ".."
        // omit user info file in user root dir
        if (entryName == DENTRY_CURRENT_DIR
            || entryName == DENTRY_PARENT_DIR
            || entryName == USER_INFO_FILE_NAME) {
            continue;
        }

        npath = path + PATH_SEPARATOR_STRING + entryName;

        if (MU_DIRECTORY == dirent.filetype) {
            // directory, call myself to delete it
            rs = rmdirRecursive(npath, pDelta);

            if (!rs.success()) {
                ERROR_LOG("path %s, rmdirRecursive() error", npath.c_str());
                return rs;
            }

        } else {
            // add file size to changed user quota
            addFileSizeToDelta(npath, pDelta);

            // delete it directly
            rt = DataNS->Unlink(npath.c_str());

            if (-1 == rt) {
                ERROR_LOG("path %s, unlink() error, %s.",
                          npath.c_str(), strerror(errno));
                return ReturnStatus(MU_FAILED, MU_UNKNOWN_ERROR);
            }
        }
    }


    // delete path

    // do not delete user root
    if (path.substr(path.length() - 1) == ROOT_PATH) {
        return ReturnStatus(MU_SUCCESS);
    }

    rt = DataNS->RmDir(path.c_str());

    if (-1 == rt) {
        ERROR_LOG("path %s, rmdir() error, %s.",
                  path.c_str(), strerror(errno));
        return ReturnStatus(MU_FAILED, MU_UNKNOWN_ERROR);
    }

    return ReturnStatus(MU_SUCCESS);
}