Skip to content

src/export.rs: GPX export missing directory creation + code reuse opportunity #26

@coderabbitai

Description

@coderabbitai

Technical Follow-ups for src/export.rs

1. Missing directory creation in GPX export

Issue: export_to_gpx doesn't call std::fs::create_dir_all(output_dir) like export_to_csv does, causing failures when exporting only GPX to a non-existent directory.

Current behavior: If a caller sets export_options.output_dir to a non-existent directory and only requests GPX export (no CSV), the export will fail with ENOENT.

Expected behavior: Should mirror the CSV behavior by creating the output directory if it doesn't exist.

Suggested fix:

let output_dir = export_options
    .output_dir
    .as_deref()
    .map(Path::new)
    .unwrap_or_else(|| input_path.parent().unwrap_or(Path::new(".")));

// Ensure output directory exists (match export_to_csv behavior)
if !output_dir.exists() {
    std::fs::create_dir_all(output_dir)?;
}

2. Optional code reuse opportunity

Suggestion: Now that compute_export_paths exists and encodes the canonical naming scheme (including the .NN suffix and .gps.gpx extension), consider avoiding duplicating the suffix logic in export_to_gpx by:

  • Passing a 1-based log_number instead of log_index and total_logs
  • Using the gpx_path from compute_export_paths instead of recomputing gpx_filename

This would keep naming and CLI status messages in lockstep with the actual GPX file path.


Location: src/export.rs lines 337-419 (export_to_gpx function)
Priority: Issue #1 is a bug fix, Issue #2 is a refactoring/DRY improvement

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions