From 89c98df68b3abf5a7aeb8718f549a30d6be3ef28 Mon Sep 17 00:00:00 2001 From: Laximas Date: Fri, 2 Feb 2024 12:13:34 +0200 Subject: [PATCH] dlt-receive: change part_num to increment only if rename was successful. If the device got disconnected and you attempted to reconnect unsuccessfully, a file rename would happen. Then in the next successful connection, it would have one extra increment in the file's name when the file size limit was reached. This commit fixes this error. Signed-off-by: Mike Konstantakos --- src/console/dlt-receive.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c index 8b1cc3bd4..4ffc304f9 100644 --- a/src/console/dlt-receive.c +++ b/src/console/dlt-receive.c @@ -284,14 +284,17 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata) char filename[PATH_MAX + 1]; filename[PATH_MAX] = 0; - snprintf(filename, PATH_MAX, "%s.%i.dlt", dltdata->ovaluebase, dltdata->part_num++); + snprintf(filename, PATH_MAX, "%s.%i.dlt", dltdata->ovaluebase, + dltdata->part_num); if (rename(dltdata->ovalue, filename) != 0) dlt_vlog(LOG_ERR, "ERROR: rename %s to %s failed with error %s\n", dltdata->ovalue, filename, strerror(errno)); - else if (dltdata->vflag) + else if (dltdata->vflag) { dlt_vlog(LOG_INFO, "Renaming existing file from %s to %s\n", dltdata->ovalue, filename); + ++dltdata->part_num; + } } /* if (file_already_exists) */ globfree(&outer);