Skip to content

Commit 416808b

Browse files
authored
fix: create missing output directories for GPX and event exports (#26) (#28)
* fix: add missing directory creation to GPX and event exports - Add std::fs::create_dir_all() to export_to_gpx before file creation - Add std::fs::create_dir_all() to export_to_event before file creation - Both functions now match export_to_csv behavior for directory handling - Fixes issue where exports to non-existent directories would fail with ENOENT Resolves: #26 * refactor: use compute_export_paths in GPX and event exports for DRY naming - Replace duplicate filename construction logic in export_to_gpx and export_to_event - Both functions now use compute_export_paths() for consistent naming with CSV exports - Reduces code duplication and improves maintainability - Ensures naming scheme stays in sync across all export formats Related to: #26
1 parent 65b64cc commit 416808b

1 file changed

Lines changed: 21 additions & 31 deletions

File tree

src/export.rs

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -369,23 +369,18 @@ pub fn export_to_gpx(
369369
return Ok(());
370370
}
371371

372-
let base_name = extract_base_name(input_path);
373-
374-
let output_dir = export_options
375-
.output_dir
376-
.as_deref()
377-
.map(Path::new)
378-
.unwrap_or_else(|| input_path.parent().unwrap_or(Path::new(".")));
379-
380-
// Use consistent naming: only add suffix for multiple logs
381-
let log_suffix = if total_logs > 1 {
382-
format!(".{:02}", log_index + 1)
383-
} else {
384-
"".to_string()
385-
};
386-
let gpx_filename = output_dir.join(format!("{}{}.gps.gpx", base_name, log_suffix));
372+
// Use compute_export_paths to ensure consistent naming with CSV exports
373+
let (_, _, gpx_path, _) =
374+
compute_export_paths(input_path, export_options, log_index + 1, total_logs);
375+
376+
// Create output directory if it doesn't exist (match export_to_csv behavior)
377+
if let Some(parent) = gpx_path.parent() {
378+
if !parent.exists() {
379+
std::fs::create_dir_all(parent)?;
380+
}
381+
}
387382

388-
let mut gpx_file = File::create(&gpx_filename)?;
383+
let mut gpx_file = File::create(&gpx_path)?;
389384
writeln!(gpx_file, r#"<?xml version="1.0" encoding="UTF-8"?>"#)?;
390385
writeln!(
391386
gpx_file,
@@ -434,23 +429,18 @@ pub fn export_to_event(
434429
return Ok(());
435430
}
436431

437-
let base_name = extract_base_name(input_path);
438-
439-
let output_dir = export_options
440-
.output_dir
441-
.as_deref()
442-
.map(Path::new)
443-
.unwrap_or_else(|| input_path.parent().unwrap_or(Path::new(".")));
432+
// Use compute_export_paths to ensure consistent naming with CSV exports
433+
let (_, _, _, event_path) =
434+
compute_export_paths(input_path, export_options, log_index + 1, total_logs);
444435

445-
// Use consistent naming: only add suffix for multiple logs
446-
let log_suffix = if total_logs > 1 {
447-
format!(".{:02}", log_index + 1)
448-
} else {
449-
"".to_string()
450-
};
451-
let event_filename = output_dir.join(format!("{}{}.event", base_name, log_suffix));
436+
// Create output directory if it doesn't exist (match export_to_csv behavior)
437+
if let Some(parent) = event_path.parent() {
438+
if !parent.exists() {
439+
std::fs::create_dir_all(parent)?;
440+
}
441+
}
452442

453-
let mut event_file = File::create(&event_filename)?;
443+
let mut event_file = File::create(&event_path)?;
454444

455445
// Export as JSONL format (individual JSON objects per line) to match blackbox_decode
456446
for event in event_frames.iter() {

0 commit comments

Comments
 (0)