Clear the buffer if no dives are present

Due to how the Oceanic ringbuffer is implemented, the ringbuffer always
contains at least one entry. If there are no dives recorded yet, the
content of that entry will be empty. Such entries are already ignored
during processing, but instead of returning this empty entry to the
caller, simply clear the logbook buffer, and return no entries at all.
This commit is contained in:
Jef Driesen 2020-02-18 22:38:50 +01:00
parent 39aad6bb52
commit 8fb0f1ca94

View File

@ -281,6 +281,7 @@ oceanic_common_device_logbook (dc_device_t *abstract, dc_event_progress_t *progr
// entries first. If an already downloaded entry is identified (by means
// of its fingerprint), the transfer is aborted immediately to reduce
// the transfer time.
unsigned int count = 0;
unsigned int nbytes = 0;
unsigned int offset = rb_logbook_size;
while (nbytes < rb_logbook_size) {
@ -312,13 +313,19 @@ oceanic_common_device_logbook (dc_device_t *abstract, dc_event_progress_t *progr
offset += layout->rb_logbook_entry_size;
break;
}
count++;
}
// Update and emit a progress event.
progress->maximum -= rb_logbook_size - nbytes;
device_event_emit (abstract, DC_EVENT_PROGRESS, progress);
dc_buffer_slice (logbook, offset, rb_logbook_size - offset);
if (count) {
dc_buffer_slice (logbook, offset, rb_logbook_size - offset);
} else {
dc_buffer_clear (logbook);
}
dc_rbstream_free (rbstream);