From a685be63958dc2a6aaacef50b459171928e09066 Mon Sep 17 00:00:00 2001 From: 0xpablo Date: Tue, 5 Dec 2023 09:07:18 +0100 Subject: [PATCH] Expose method to repair the DB --- Code/RocksDB.h | 4 ++++ Code/RocksDB.mm | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Code/RocksDB.h b/Code/RocksDB.h index 35acc51..3a8c2f0 100644 --- a/Code/RocksDB.h +++ b/Code/RocksDB.h @@ -590,6 +590,10 @@ typedef void (^RestoreBlock)(NSError * __autoreleasing *); - (nullable id)withBulkLoad:(id (NS_NOESCAPE ^)(void))actionBlock error:(NSError * __autoreleasing *)error; +#pragma mark - Repair + ++ (BOOL)repairDB:(NSString *)dbPath options:(RocksDBOptions *)options error:(NSError **)error; + @end NS_ASSUME_NONNULL_END diff --git a/Code/RocksDB.mm b/Code/RocksDB.mm index b3becde..93ce907 100644 --- a/Code/RocksDB.mm +++ b/Code/RocksDB.mm @@ -804,4 +804,19 @@ - (nullable id)withBulkLoad:(id (NS_NOESCAPE ^)(void))actionBlock return result; } +#pragma mark - Repair + ++ (BOOL)repairDB:(NSString *)dbPath options:(RocksDBOptions *)options error:(NSError **)error { + rocksdb::Status s = rocksdb::RepairDB(dbPath.UTF8String, options.options); + + if (!s.ok()) { + if (error != NULL) { + *error = [RocksDBError errorWithRocksStatus:s]; + } + return NO; + } + + return YES; +} + @end