Skip to content

Commit 05da01d

Browse files
committed
Generate default.db-options file if it not exist, #4671
Signed-off-by: Eval EXEC <[email protected]>
1 parent c49fdbf commit 05da01d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

ckb-bin/src/subcommand/run.rs

+23
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ use ckb_async_runtime::{new_global_runtime, Handle};
66
use ckb_build_info::Version;
77
use ckb_launcher::Launcher;
88
use ckb_logger::info;
9+
use ckb_resource::{Resource, TemplateContext};
910

1011
use ckb_stop_handler::{broadcast_exit_signals, wait_all_ckb_services_exit};
1112

1213
use ckb_types::core::cell::setup_system_cell_cache;
1314

1415
pub fn run(args: RunArgs, version: Version, async_handle: Handle) -> Result<(), ExitCode> {
16+
check_default_db_options_exists(&args)?;
1517
deadlock_detection();
1618

1719
let rpc_threads_num = calc_rpc_threads_num(&args);
@@ -79,3 +81,24 @@ fn calc_rpc_threads_num(args: &RunArgs) -> usize {
7981
let default_num = usize::max(system_parallelism, 1);
8082
args.config.rpc.threads.unwrap_or(default_num)
8183
}
84+
85+
fn check_default_db_options_exists(args: &RunArgs) -> Result<(), ExitCode> {
86+
// check is there a default.db-options file exist in args.config.root_dir, if not, create one.
87+
let db_options_path = args.config.root_dir.join("default.db-options");
88+
89+
// Check if the default.db-options file exists, if not, create one.
90+
if !db_options_path.exists() {
91+
warn!(
92+
"default.db-options file does not exist in {}, creating one.",
93+
args.config.root_dir
94+
);
95+
// context_for_db_options is used to generate a default default.db-options file.
96+
let context_for_db_options = TemplateContext::new("", vec![]);
97+
98+
// Attempt to export the bundled DB options to the specified path.
99+
Resource::bundled_db_options()
100+
.export(&context_for_db_options, &args.config.root_dir)
101+
.map_err(|_| ExitCode::Config)?;
102+
}
103+
Ok(())
104+
}

0 commit comments

Comments
 (0)