static bool removeRecursive(const QString &pathname)
{
    QFileInfo fi(pathname);
    if (!fi.exists())
        return true;

    if (fi.isFile())
        return QFile::remove(pathname);

    if (!fi.isDir()) {
        //  not a file or directory. How do I remove it?
        return false;
    }

    // not empty -- we must empty it first
    QDirIterator di(pathname, QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
    while (di.hasNext()) {
        di.next();
        if (!di.fileInfo().exists() && !di.fileInfo().isSymLink())
            continue;
        bool ok;
        if (di.fileInfo().isFile() || di.fileInfo().isSymLink())
            ok = QFile::remove(di.filePath());
        else
            ok = removeRecursive(di.filePath());
        if (!ok) {
            return false;
        }
    }

    QDir dir(pathname);
    QString dirname = dir.dirName();
    dir.cdUp();
    return dir.rmdir(dirname);
}
Exemplo n.º 2
0
void removeRecursive( trieNode<T>* curr, std::string key, int level )
{
    //Create a node to keep track of the root 
    trieNode<T>* currRoot = curr;
    //Set the leaf of the key to false
    if( level == key.size() - 1 )
        curr->children[key[level] - 97]->isLeaf = false;
    //If the current node is not NULL and our current level is not past the end of the key
    if( curr != NULL && level != key.size() - 1 )
    {
        //Set curr to the next letter in the key
        curr = curr->children[ key[level] - 97 ];
        //Recursivly call removeRecursive while incrementing the level by 1
        removeRecursive( curr, key, ++level );
        //If the node corresponding to the next letter in the key has no children delete it
        if( checkChildren( curr->children[key[level] - 97] ) )
        {
            delete curr->children[key[level] - 97];
            curr->children[key[level] - 97] = NULL;
        }
    }
    //If the node corresponding to the first letter in the key has no children delete it
    if( level - 1 == 0 )
    {
        if( checkChildren( currRoot->children[key[0] - 97] ) )
        {
            delete currRoot->children[ key[0] - 97 ];
            currRoot->children[ key[0] - 97 ] = NULL;
        }
    }
}
Exemplo n.º 3
0
static TNode *removeRecursive(TNode *pRoot, const void *pKey, CompareFunc compare)
{
    int result;
    TNode *pNodeSuccessor, *pNodeDelete;

    if (pRoot != NULL)
    {
        if ((result = compare(pRoot->pData, pKey)) > 0)
        {
            pRoot->pLeft = removeRecursive(pRoot->pLeft, pKey, compare);
        }
        else if (result < 0)
        {
            pRoot->pRight = removeRecursive(pRoot->pRight, pKey, compare);
        }
        else
        {
            if (pRoot->pLeft == NULL)
            {
                pNodeDelete = pRoot;
                pRoot = pRoot->pRight;
                delete pNodeDelete;
            }
            else if (pRoot->pRight == NULL)
            {
                pNodeDelete = pRoot;
                pRoot = pRoot->pLeft;
                delete pNodeDelete;
            }
            else
            {
                pNodeSuccessor = getInorderSuccessor(pRoot->pRight);
                pRoot->pData   = pNodeSuccessor->pData;
                pRoot->pRight  = removeRecursive(pRoot->pRight, pNodeSuccessor->pData, compare);
            }
        }
        return pRoot;
    }
    else
    {
        return NULL;
    }    
}
Exemplo n.º 4
0
/*
 *	Method:
 *	void Trie::removeRecursive( Trie_Node *node )
 *
 *	Purpose:
 *	Recursive removal, to be used by the destructor.
 *
 *	Input:
 *	as described
 *
 *	Output:
 *	none
 */
void Trie::removeRecursive( Trie_Node *node )
{
	Trie_Node *temp;

	while( NULL != node ) {
		removeRecursive( node->child );
		temp = node;
		node = node->sibling;
		delete temp;
	};
}
Exemplo n.º 5
0
bool Trie<T>::remove( std::string key )
{
    trieNode<T>* curr = root;
    //Check that the key exists in the trie
    for( int i = 0; i < key.size(); ++i )
    {
        if( curr->children[ key[i] - 97 ] == NULL )
            return false;
        curr = curr->children[ key[i] - 97 ];
    }
    //Call removeRecursive
    removeRecursive( root, key, 0 );
    return true;
}
Exemplo n.º 6
0
void CTxMemPool::removeConflicts(const CTransaction &tx)
{
    // Remove transactions which depend on inputs of tx, recursively
    LOCK(cs);
    for (const CTxIn &txin : tx.vin) {
        auto it = mapNextTx.find(txin.prevout);
        if (it != mapNextTx.end()) {
            const CTransaction &txConflict = *it->second;
            if (txConflict != tx)
            {
                ClearPrioritisation(txConflict.GetHash());
                removeRecursive(txConflict, MemPoolRemovalReason::CONFLICT);
            }
        }
    }
}
Exemplo n.º 7
0
/*
 *	Method:
 *	Trie::~Trie(void)
 *
 *	Purpose:
 *	Destructor of the trie. Recursively frees all memory starting from
 *	the root of the trie.
 *
 *	Input:
 *	none
 *
 *	Output:
 *	none
 */
Trie::~Trie(void)
{
	removeRecursive(root);
	root = NULL;
}
Exemplo n.º 8
0
bool BTreeRemove(BTree *pTree, const void *pKey)
{
    return (removeRecursive(pTree->pRoot, pKey, pTree->compare) != NULL);
}