Skip to content

Commit

Permalink
dlt-receive: change part_num to increment only if rename was successful.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Laximas committed Feb 2, 2024
1 parent 6e66d7e commit 89c98df
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/console/dlt-receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 89c98df

Please sign in to comment.