diff --git a/HISTORY.md b/HISTORY.md index 5e510ee2e..4bea93fb9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -70,6 +70,7 @@ * Introduced an option `BlockBasedTableBuilder::detect_filter_construct_corruption` for detecting corruption during Bloom Filter (format_version >= 5) and Ribbon Filter construction. * Improved the SstDumpTool to read the comparator from table properties and use it to read the SST File. * Extended the column family statistics in the info log so the total amount of garbage in the blob files and the blob file space amplification factor are also logged. Also exposed the blob file space amp via the `rocksdb.blob-stats` DB property. +* Introduced the API rocksdb_create_dir_if_missing in c.h that calls underlying file system's CreateDirIfMissing API to create the directory. ## 6.29.0 (01/21/2022) Note: The next release will be major release 7.0. See https://github.com/facebook/rocksdb/issues/9390 for more info. diff --git a/db/c.cc b/db/c.cc index aa48708d6..c6f23adf2 100644 --- a/db/c.cc +++ b/db/c.cc @@ -4321,6 +4321,11 @@ rocksdb_sstfilewriter_t* rocksdb_sstfilewriter_create( return writer; } +void rocksdb_create_dir_if_missing(rocksdb_env_t* env, const char* path, + char** errptr) { + SaveError(errptr, env->rep->CreateDirIfMissing(std::string(path))); +} + rocksdb_sstfilewriter_t* rocksdb_sstfilewriter_create_with_comparator( const rocksdb_envoptions_t* env, const rocksdb_options_t* io_options, const rocksdb_comparator_t* /*comparator*/) { diff --git a/db/c_test.c b/db/c_test.c index eaff94f19..8b224e049 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -447,6 +447,10 @@ int main(int argc, char** argv) { cmp = rocksdb_comparator_create(NULL, CmpDestroy, CmpCompare, CmpName); dbpath = rocksdb_dbpath_create(dbpathname, 1024 * 1024); env = rocksdb_create_default_env(); + + rocksdb_create_dir_if_missing(env, GetTempDir(), &err); + CheckNoError(err); + cache = rocksdb_cache_create_lru(100000); options = rocksdb_options_create(); diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index f0d32bd41..9d9e999ca 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -1818,6 +1818,8 @@ extern ROCKSDB_LIBRARY_API rocksdb_envoptions_t* rocksdb_envoptions_create( void); extern ROCKSDB_LIBRARY_API void rocksdb_envoptions_destroy( rocksdb_envoptions_t* opt); +extern ROCKSDB_LIBRARY_API void rocksdb_create_dir_if_missing( + rocksdb_env_t* env, const char* path, char** errptr); /* SstFile */