From 4d2759dc9a1761f8ef3ee35fd319adb134f18f3e Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Mon, 14 Jul 2025 14:40:01 +0300 Subject: [PATCH] More consistent handling of open options --- crates/node/src/geth.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/node/src/geth.rs b/crates/node/src/geth.rs index 47a5a93..8409ec3 100644 --- a/crates/node/src/geth.rs +++ b/crates/node/src/geth.rs @@ -107,19 +107,21 @@ impl Instance { /// [Instance::init] must be called prior. #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] fn spawn_process(&mut self) -> anyhow::Result<&mut Self> { - // Options to re-create and re-write to the file starting at offset zero. We do not want to - // re-use log files between runs. Users that want to keep their log files should pass in a - // different working directory between runs. - let stdout_logs_file = OpenOptions::new() - .create(true) - .truncate(true) - .write(true) + // This is the `OpenOptions` that we wish to use for all of the log files that we will be + // opening in this method. We need to construct it in this way to: + // 1. Be consistent + // 2. Less verbose and more dry + // 3. Because the builder pattern uses mutable references so we need to get around that. + let open_options = { + let mut options = OpenOptions::new(); + options.create(true).truncate(true).write(true); + options + }; + + let stdout_logs_file = open_options + .clone() .open(self.geth_stdout_log_file_path())?; - let stderr_logs_file = OpenOptions::new() - .create(true) - .truncate(true) - .write(true) - .open(self.geth_stderr_log_file_path())?; + let stderr_logs_file = open_options.open(self.geth_stderr_log_file_path())?; self.handle = Exec::cmd(&self.geth) .arg("--dev") .arg("--datadir")