Skip to content

Commit a11af84

Browse files
committed
fix: accept total_logs parameter in export_to_event function
Remove incorrect local calculation of total_logs from log_index and accept it as a parameter instead. This fixes the bug where log_index=0 would incorrectly be treated as a single-log scenario even in multi-log files. The log suffix is now only appended when total_logs > 1, ensuring correct naming for multi-log exports. Updates all callers in examples and documentation to pass the correct total_logs value from their context.
1 parent d5caa32 commit a11af84

5 files changed

Lines changed: 12 additions & 5 deletions

File tree

CRATE_USAGE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ fn main() -> anyhow::Result<()> {
167167
export_to_event(
168168
Path::new("flight.BBL"),
169169
0, // log index
170+
1, // total_logs
170171
&log.event_frames,
171172
&export_opts
172173
)?;
@@ -206,7 +207,7 @@ fn main() -> anyhow::Result<()> {
206207

207208
// Export events if event data exists
208209
if !log.event_frames.is_empty() {
209-
export_to_event(input_path, 0, &log.event_frames, &export_opts)?;
210+
export_to_event(input_path, 0, log.total_logs, &log.event_frames, &export_opts)?
210211
}
211212

212213
println!("All exports completed successfully");

examples/event_export.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fn main() -> anyhow::Result<()> {
4444
export_to_event(
4545
Path::new(&input_file),
4646
0, // log index
47+
1, // total_logs (assuming single log for this example)
4748
&log.event_frames,
4849
&export_opts,
4950
)?;

examples/export_demo.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ fn main() -> Result<()> {
123123
log.log_number
124124
)
125125
})?;
126-
export_to_event(input_path, log_index, &log.event_frames, &export_opts)?;
126+
export_to_event(
127+
input_path,
128+
log_index,
129+
log.total_logs,
130+
&log.event_frames,
131+
&export_opts,
132+
)?;
127133
println!("✓ Event export complete");
128134

129135
// Display sample events

examples/multi_export.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ fn main() -> anyhow::Result<()> {
9999
export_to_event(
100100
Path::new(&input_file),
101101
log.log_number - 1,
102+
log.total_logs,
102103
&log.event_frames,
103104
&export_opts,
104105
)?;

src/export.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ pub fn export_to_gpx(
380380
pub fn export_to_event(
381381
input_path: &Path,
382382
log_index: usize,
383+
total_logs: usize,
383384
event_frames: &[EventFrame],
384385
export_options: &ExportOptions,
385386
) -> Result<()> {
@@ -398,9 +399,6 @@ pub fn export_to_event(
398399
.map(Path::new)
399400
.unwrap_or_else(|| input_path.parent().unwrap_or(Path::new(".")));
400401

401-
// Determine total logs from context (if log_index is 0, assume single log)
402-
let total_logs = if log_index > 0 { log_index + 1 } else { 1 };
403-
404402
// Use consistent naming: only add suffix for multiple logs
405403
let log_suffix = if total_logs > 1 {
406404
format!(".{:02}", log_index + 1)

0 commit comments

Comments
 (0)