Skip to content

Commit d626b15

Browse files
authored
dlt-receive: change part_num to increment only if rename was successful. (#593)
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 <[email protected]>
1 parent 489ef5d commit d626b15

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/console/dlt-receive.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,17 @@ int dlt_receive_open_output_file(DltReceiveData *dltdata)
284284
char filename[PATH_MAX + 1];
285285
filename[PATH_MAX] = 0;
286286

287-
snprintf(filename, PATH_MAX, "%s.%i.dlt", dltdata->ovaluebase, dltdata->part_num++);
287+
snprintf(filename, PATH_MAX, "%s.%i.dlt", dltdata->ovaluebase,
288+
dltdata->part_num);
288289

289290
if (rename(dltdata->ovalue, filename) != 0)
290291
dlt_vlog(LOG_ERR, "ERROR: rename %s to %s failed with error %s\n",
291292
dltdata->ovalue, filename, strerror(errno));
292-
else if (dltdata->vflag)
293+
else if (dltdata->vflag) {
293294
dlt_vlog(LOG_INFO, "Renaming existing file from %s to %s\n",
294295
dltdata->ovalue, filename);
296+
++dltdata->part_num;
297+
}
295298
} /* if (file_already_exists) */
296299

297300
globfree(&outer);

0 commit comments

Comments
 (0)