Relax checks before executing the -T/-U operations

Now that terminal commands can create files, some of the checks before
executing the -T/-U operations need to be relaxed to avoid false errors.
The command below is perfectly fine, because the file to be read from in
the -U step will be created earlier.

$ rm -f /tmp/load.eep
$ avrdude -qq -cdryrun -pm328p \
  -T 'w ee 0 "avrdude"; save ee 0 8 /tmp/load.eep:h' \
  -U eeprom:w:/tmp/load.eep
This commit is contained in:
stefanrueger
2023-06-15 00:44:31 +01:00
parent b296c82185
commit 14aba8ad65

View File

@@ -280,13 +280,16 @@ static void ioerror(const char *iotype, const UPDATE *upd) {
// Basic checks to reveal serious failure before programming (and on autodetect set format)
int update_dryrun(const AVRPART *p, UPDATE *upd) {
static char **wrote;
static int nfwritten;
static const char **wrote, **termcmds;
static int nfwritten, nterms;
int known, format_detect, ret = LIBAVRDUDE_SUCCESS;
if(upd->cmdline) // Todo: parse terminal command line?
if(upd->cmdline) { // Todo: parse terminal command line?
termcmds = realloc(termcmds, sizeof(*termcmds) * (nterms+1));
termcmds[nterms++] = upd->cmdline;
return 0;
}
/*
* Reject an update if memory name is not known amongst any part (suspect a typo)
@@ -304,27 +307,35 @@ int update_dryrun(const AVRPART *p, UPDATE *upd) {
if(upd->format != FMT_IMM) {
// Need to read the file: was it written before, so will be known?
for(int i = 0; i < nfwritten; i++)
if(!wrote || (upd->filename && !strcmp(wrote[i], upd->filename)))
if(!wrote || (upd->filename && str_eq(wrote[i], upd->filename)))
known = 1;
// Could a -T terminal command have created the file?
for(int i = 0; i < nterms; i++)
if(!termcmds || (upd->filename && str_contains(termcmds[i], upd->filename)))
known = 1;
// Any -t interactive terminal could have created it
for(int i = 0; i < nterms; i++)
if(!termcmds || str_eq(termcmds[i], "interactive terminal"))
known = 1;
errno = 0;
if(!known && !update_is_readable(upd->filename)) {
ioerror("readable", upd);
ret = LIBAVRDUDE_GENERAL_FAILURE;
known = 1; // Pretend we know it, so no auto detect needed
ret = LIBAVRDUDE_SOFTFAIL; // Even so it might still be there later on
known = 1; // Pretend we know it, so no auto detect needed
}
}
}
if(!known && upd->format == FMT_AUTO) {
if(!strcmp(upd->filename, "-")) {
if(str_eq(upd->filename, "-")) {
pmsg_error("cannot auto detect file format for stdin/out, specify explicitly\n");
ret = LIBAVRDUDE_GENERAL_FAILURE;
} else if((format_detect = fileio_fmt_autodetect(upd->filename)) < 0) {
pmsg_error("cannot determine file format for %s, specify explicitly\n", upd->filename);
ret = LIBAVRDUDE_GENERAL_FAILURE;
pmsg_warning("cannot determine file format for %s, specify explicitly\n", upd->filename);
ret = LIBAVRDUDE_SOFTFAIL;
} else {
// Set format now, no need to repeat auto detection later
// Set format now (but might be wrong in edge cases, where user needs to specify explicity)
upd->format = format_detect;
if(quell_progress < 2)
pmsg_notice("%s file %s auto detected as %s\n",
@@ -342,9 +353,9 @@ int update_dryrun(const AVRPART *p, UPDATE *upd) {
errno = 0;
if(!update_is_writeable(upd->filename)) {
ioerror("writeable", upd);
ret = LIBAVRDUDE_GENERAL_FAILURE;
ret = LIBAVRDUDE_SOFTFAIL;
} else if(upd->filename) { // Record filename (other than stdout) is available for future reads
if(strcmp(upd->filename, "-") && (wrote = realloc(wrote, sizeof(*wrote) * (nfwritten+1))))
if(!str_eq(upd->filename, "-") && (wrote = realloc(wrote, sizeof(*wrote) * (nfwritten+1))))
wrote[nfwritten++] = upd->filename;
}
}