void btreeEraseNode(BTreeNode *node) { GdbBlock *block; if (node == NULL || node->block->offset == 0) { return; } block = node->block; gdbFreeBlock(block->db, block->offset, block->type); #if 0 rawFileSeek(block->db->fp, block->offset, SEEK_SET); gdbPad(block->db->fp, block->size); #endif }
GdbStatus gdbAddTree(GDatabase *db, BTree *tree, const char *key, BTree **newTree) { GdbStatus status; offset_t offset; short blockSize; blocktype_t type; if (db == NULL || tree == NULL || db->fp == NULL || key == NULL || newTree == NULL) { return GDB_ERROR; } *newTree = btreeCreate(db, 5); offset = (*newTree)->block->offset; blockSize = (*newTree)->block->multiple; type = (*newTree)->block->type; if (*newTree == NULL) { *newTree = NULL; return GDB_ERROR; } status = btreeInsert(tree, key, offset, 0); if (status == GDB_DUPLICATE) { /* Return the existing newTree. */ btreeClose(*newTree); gdbFreeBlock(db, offset, type); offset = btreeSearch(tree, key); if (offset == 0) { /* I doubt this will ever happen. */ pmError(PM_ERROR_FATAL, _("GNUpdate DB: Possible database corruption! Back up " "your database and contact a developer.\n")); exit(1); } *newTree = btreeOpen(db, offset); status = GDB_SUCCESS; } else if (status == GDB_ERROR) { btreeClose(*newTree); fseek(db->fp, offset, SEEK_SET); #if 0 gdbPad(db->fp, blockSize); #endif gdbFreeBlock(db, offset, type); *newTree = NULL; } return status; }