diff --git a/qbolt/boltdb.cpp b/qbolt/boltdb.cpp index b908925..ad472a5 100644 --- a/qbolt/boltdb.cpp +++ b/qbolt/boltdb.cpp @@ -52,8 +52,23 @@ bool BoltDB::addBucket(QStringList bucketPath, QByteArray bucketName, QString& e bool BoltDB::deleteBucket(QStringList bucketPath, QByteArray bucketName, QString& errorOut) { - errorOut = "Not implemented"; - return false; // not implemented + GoSliceManagedWrapper browse(&bucketPath); + GoString bucketNameGS = Interop::toGoString_WeakRef(&bucketName); + auto resp = ::Bolt_DeleteBucket(this->gmsDbRef, browse.slice, bucketNameGS); + + if (resp.r0 == ERROR_AND_STOP_CALLING) { + errorOut = QString::fromUtf8(resp.r1, resp.r2); + free(resp.r1); + return false; + + } else if (resp.r0 == FINISHED_OK) { + return true; + + } else { + // ?? unreachable + return false; + + } } bool BoltDB::listBucketsAtRoot(QString& errorOut, NameReciever cb) diff --git a/qbolt/mainwindow.cpp b/qbolt/mainwindow.cpp index 9879a2d..aa2b372 100644 --- a/qbolt/mainwindow.cpp +++ b/qbolt/mainwindow.cpp @@ -366,10 +366,25 @@ void MainWindow::on_actionDelete_bucket_triggered() auto *bdb = GET_BDB(top); // Prompt for confirmation - - if (QMessageBox::question(this, tr("Delete bucket"), tr("Are you sure you want to remove the bucket '%s'?").arg(itm->text(0)), QMessageBox::Yes, QMessageBox::Cancel) != QMessageBox::Yes) { + QString bucketToDelete = itm->text(0); + if (QMessageBox::question(this, tr("Delete bucket"), tr("Are you sure you want to remove the bucket '%1'?").arg(bucketToDelete), QMessageBox::Yes, QMessageBox::Cancel) != QMessageBox::Yes) { return; } + // One level down + + browse.pop_back(); + + QString err; + if (! bdb->deleteBucket(browse, bucketToDelete.toUtf8(), err)) { + QMessageBox qmb; + qmb.setText(tr("Error removing bucket: %1").arg(err)); + qmb.exec(); + return; + } + + // Refresh bucket list + refreshBucketTree(itm->parent()); // sub-tree only + ui->bucketTree->expandItem(itm->parent()); }