From 6caf3b8e4b2fde75c1033f503065be3824a9ee50 Mon Sep 17 00:00:00 2001 From: Chip Turner Date: Wed, 21 Nov 2012 13:26:32 -0800 Subject: [PATCH] Fix broken test; some ldb commands can run without a db_ Summary: It would appear our unit tests make use of code from ldb_cmd, and don't always require a valid database handle. D6855 was not aware db_ could sometimes be NULL for such commands, and so it broke reduce_levels_test. This moves the check elsewhere to (at least) fix the 'ldb dump' case of segfaulting when it couldn't open a database. Test Plan: make check Reviewers: dhruba Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D6903 --- util/ldb_cmd.cc | 3 +++ util/ldb_cmd.h | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/util/ldb_cmd.cc b/util/ldb_cmd.cc index fabdda1cb6..5c33d6c768 100644 --- a/util/ldb_cmd.cc +++ b/util/ldb_cmd.cc @@ -126,6 +126,9 @@ void DBDumper::Help(std::string& ret) { } void DBDumper::DoCommand() { + if (!db_) { + return; + } // Parse command line args uint64_t count = 0; if (print_stats_) { diff --git a/util/ldb_cmd.h b/util/ldb_cmd.h index a6d664fb8e..349f56cd47 100644 --- a/util/ldb_cmd.h +++ b/util/ldb_cmd.h @@ -134,10 +134,6 @@ public: OpenDB(); } - if (!db_) { - return; - } - DoCommand(); if (exec_state_.IsNotStarted()) { exec_state_ = LDBCommandExecuteResult::SUCCEED("");