From 8fb0f1ca94c2c95c232583cc807a28c95c2c229a Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 18 Feb 2020 22:38:50 +0100 Subject: [PATCH] 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. --- src/oceanic_common.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 48ed61a..817e3e2 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -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);