diff --git a/ChangeLog b/ChangeLog index 55b1cbfe..dcd4b527 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ v0.39.5 24-Dec-2003 common.a: Allows node locking with zero bytes lockfiles created by some other OS when enabled in the setup. + The attach function now checks if a file is already attached. mbcico: Binkp code cleanup. diff --git a/lib/attach.c b/lib/attach.c index d28eb53e..ce3e25b9 100644 --- a/lib/attach.c +++ b/lib/attach.c @@ -4,7 +4,7 @@ * Purpose ...............: Attach files to outbound * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -41,7 +41,7 @@ int attach(faddr noden, char *ofile, int mode, char flavor) { FILE *fp; - char *flofile; + char *flofile, *thefile; int rc; if (ofile == NULL) @@ -53,6 +53,7 @@ int attach(faddr noden, char *ofile, int mode, char flavor) } flofile = calloc(PATH_MAX, sizeof(char)); + thefile = calloc(PATH_MAX, sizeof(char)); sprintf(flofile, "%s", floname(&noden, flavor)); /* @@ -74,6 +75,7 @@ int attach(faddr noden, char *ofile, int mode, char flavor) WriteError("$Can't open %s", flofile); WriteError("May be locked by mbcico"); free(flofile); + free(thefile); return FALSE; } @@ -81,39 +83,54 @@ int attach(faddr noden, char *ofile, int mode, char flavor) case LEAVE: if (strlen(CFG.dospath)) { if (CFG.leavecase) - fprintf(fp, "%s\r\n", Unix2Dos(ofile)); + sprintf(thefile, "%s", Unix2Dos(ofile)); else - fprintf(fp, "%s\r\n", tu(Unix2Dos(ofile))); + sprintf(thefile, "%s", tu(Unix2Dos(ofile))); } else { - fprintf(fp, "%s\r\n", ofile); + sprintf(thefile, "%s", ofile); } break; case KFS: if (strlen(CFG.dospath)) { if (CFG.leavecase) - fprintf(fp, "^%s\r\n", Unix2Dos(ofile)); + sprintf(thefile, "^%s", Unix2Dos(ofile)); else - fprintf(fp, "^%s\r\n", tu(Unix2Dos(ofile))); + sprintf(thefile, "^%s", tu(Unix2Dos(ofile))); } else { - fprintf(fp, "^%s\r\n", ofile); + sprintf(thefile, "^%s", ofile); } break; case TFS: if (strlen(CFG.dospath)) { if (CFG.leavecase) - fprintf(fp, "#%s\r\n", Unix2Dos(ofile)); + sprintf(thefile, "#%s", Unix2Dos(ofile)); else - fprintf(fp, "#%s\r\n", tu(Unix2Dos(ofile))); + sprintf(thefile, "#%s", tu(Unix2Dos(ofile))); } else { - fprintf(fp, "#%s\r\n", ofile); + sprintf(thefile, "#%s", ofile); } break; } + fseek(fp, 0, SEEK_SET); + while (fgets(flofile, PATH_MAX -1, fp) != NULL) { + Striplf(flofile); + if (strncmp(flofile, thefile, strlen(thefile)) == 0) { + fclose(fp); + Syslog('+', "attach: file %s already attached", ofile); + free(flofile); + free(thefile); + return TRUE; + } + } + + fseek(fp, 0, SEEK_END); + fprintf(fp, "%s\r\n", thefile); fclose(fp); free(flofile); + free(thefile); return TRUE; } diff --git a/mbcico/binkpnew.c b/mbcico/binkpnew.c index 875025ee..d5fb49d0 100644 --- a/mbcico/binkpnew.c +++ b/mbcico/binkpnew.c @@ -814,8 +814,9 @@ SM_RETURN */ int file_transfer(void) { - int rc = 0, complete = FALSE; - TrType Trc = Ok; + int rc = 0, complete = FALSE; + TrType Trc = Ok; + binkp_list *tmp; for (;;) { Syslog('B', "Binkp: FileTransfer state %s", ftstate[bp.FtState]); @@ -894,7 +895,23 @@ int file_transfer(void) } break; - case DeinitTransfer:/* Clear current filelist */ + case DeinitTransfer:/* + * In case of a transfer error the filelist is not yet cleared + */ + if (tosend != NULL) { + Syslog('b', "Clear current filelist"); + for (tmp = bll; bll; bll = tmp) { + tmp = bll->next; + if (bll->local) + free(bll->local); + if (bll->remote) + free(bll->remote); + free(bll); + } + + tidy_filelist(tosend, TRUE); + tosend = NULL; + } if (bp.rc) return MBERR_FTRANSFER; else @@ -1354,23 +1371,6 @@ TrType binkp_transmitter(void) if (tosend != NULL) { Syslog('b', "Clear current filelist"); - debug_binkp_list(&bll); - - /* - * Process all send files. - */ - for (tsl = tosend; tsl; tsl = tsl->next) { - if (tsl->remote == NULL) { - execute_disposition(tsl); - } else { - for (tmp = bll; tmp; tmp = tmp->next) { - if ((strcmp(tmp->local, tsl->local) == 0) && (tmp->state == Got)) { - execute_disposition(tsl); - } - } - } - } - for (tmp = bll; bll; bll = tmp) { tmp = bll->next; if (bll->local) @@ -1749,6 +1749,7 @@ int binkp_process_messages(void) { the_queue *tmpq, *oldq; binkp_list *tmp; + file_list *tsl; int Found; char *lname; time_t ltime; @@ -1828,6 +1829,15 @@ int binkp_process_messages(void) Syslog('+', "Binkp: remote GOT \"%s\"", tmp->remote); } tmp->state = Got; + for (tsl = tosend; tsl; tsl = tsl->next) { + if (tsl->remote == NULL) { + execute_disposition(tsl); + } else { + if (strcmp(tmp->local, tsl->local) == 0) { + execute_disposition(tsl); + } + } + } break; } } @@ -1854,7 +1864,7 @@ int binkp_process_messages(void) } } if (!Found) { - Syslog('!', "Binkp: unexpected M_GOT \"%s\"", tmpq->data); /* Ignore frame */ + Syslog('!', "Binkp: unexpected M_SKIP \"%s\"", tmpq->data); /* Ignore frame */ } } else { /* Illegal message on the queue */