Skip to content

Commit 5cc8429

Browse files
dcgclaude
authored andcommitted
fix(dash-spv): use temporary directory by default instead of ./dash-spv-data
Changes the default data directory behavior to create unique temporary directories in /tmp rather than using ./dash-spv-data in the project directory. This prevents cluttering the workspace and aligns with test behavior. - Default: Creates /tmp/dash-spv-{timestamp}-{pid} directory - Explicit: --data-dir flag still works for custom paths - Tests: Already use TempDir and are unaffected 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 9e9a406 commit 5cc8429

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

dash-spv/src/main.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
5151
.short('d')
5252
.long("data-dir")
5353
.value_name("DIR")
54-
.help("Data directory for storage")
55-
.default_value("./dash-spv-data"),
54+
.help("Data directory for storage (default: unique directory in /tmp)"),
5655
)
5756
.arg(
5857
Arg::new("peer")
@@ -143,10 +142,20 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
143142
};
144143

145144
// Create configuration
146-
let data_dir_str = matches.get_one::<String>("data-dir").ok_or("Missing data-dir argument")?;
147-
let data_dir = PathBuf::from(data_dir_str);
145+
let data_dir = if let Some(data_dir_str) = matches.get_one::<String>("data-dir") {
146+
PathBuf::from(data_dir_str)
147+
} else {
148+
// Create a unique temp directory with timestamp and process ID
149+
let timestamp = std::time::SystemTime::now()
150+
.duration_since(std::time::UNIX_EPOCH)
151+
.unwrap_or_default()
152+
.as_secs();
153+
let pid = std::process::id();
154+
let dir_name = format!("dash-spv-{}-{}", timestamp, pid);
155+
std::env::temp_dir().join(dir_name)
156+
};
148157
let mut config = ClientConfig::new(network)
149-
.with_storage_path(data_dir)
158+
.with_storage_path(data_dir.clone())
150159
.with_validation_mode(validation_mode)
151160
.with_log_level(log_level);
152161

@@ -206,6 +215,9 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
206215

207216
// Initialize logging first (without terminal UI)
208217
dash_spv::init_logging(log_level)?;
218+
219+
// Log the data directory being used
220+
tracing::info!("Using data directory: {}", data_dir.display());
209221

210222
// Create and start the client
211223
let mut client = match DashSpvClient::new(config).await {

0 commit comments

Comments
 (0)