563e8c19187e14db5892151af576c16bfe756405 kent Sat Apr 13 17:48:42 2013 -0700 Adding a separate parameter for file name to report errors on for benefit of edwSubmit which want's to report pre-upload URL where error occurs. diff --git src/lib/fieldedTable.c src/lib/fieldedTable.c index d2aadf2..a70f6a4 100644 --- src/lib/fieldedTable.c +++ src/lib/fieldedTable.c @@ -49,54 +49,73 @@ struct fieldedRow *fr; lmAllocVar(lm, fr); lmAllocArray(lm, fr->row, rowSize); fr->id = id; int i; for (i=0; i<rowSize; ++i) fr->row[i] = lmCloneString(lm, row[i]); /* Add it to end of list using cursor to avoid slReverse hassles. */ *(table->cursor) = fr; table->cursor = &fr->next; return fr; } -struct fieldedTable *fieldedTableFromTabFile(char *url, char *requiredFields[], int requiredCount) +struct fieldedTable *fieldedTableFromTabFile(char *fileName, char *reportFileName, + char *requiredFields[], int requiredCount) /* Read table from tab-separated file with a #header line that defines the fields. Ensures - * all requiredFields (if any) are present. */ + * all requiredFields (if any) are present. The reportFileName is just used for error reporting and + * should be NULL for most purposes. This is used by edwSubmit though which + * first copies to a local file, and we want to report errors from the remote file. + * We do know the remote file exists at least, because we just copied it. */ { -struct lineFile *lf = lineFileOpen(url, TRUE); -char *line; +/* Open file with fileName */ +struct lineFile *lf = lineFileOpen(fileName, TRUE); + +/* Substitute in reportFileName for error reporting */ +if (reportFileName != NULL) + { + if (differentString(reportFileName, fileName)) + { + freeMem(lf->fileName); + lf->fileName = cloneString(reportFileName); + } + } +else + { + reportFileName = fileName; + } /* Get first line and turn it into field list. */ +char *line; if (!lineFileNext(lf, &line, NULL)) - errAbort("%s is empty", url); + errAbort("%s is empty", reportFileName); if (line[0] != '#') - errAbort("%s must start with '#' and field names on first line", url); + errAbort("%s must start with '#' and field names on first line", reportFileName); line = skipLeadingSpaces(line+1); int fieldCount = chopByChar(line, '\t', NULL, 0); char *fields[fieldCount]; chopTabs(line, fields); /* Make sure that all required fields are present. */ int i; for (i = 0; i < requiredCount; ++i) { char *required = requiredFields[i]; int ix = stringArrayIx(required, fields, fieldCount); if (ix < 0) - errAbort("%s is missing required field '%s'", url, required); + errAbort("%s is missing required field '%s'", reportFileName, required); } /* Create fieldedTable . */ -struct fieldedTable *table = fieldedTableNew(url, fields, fieldCount); +struct fieldedTable *table = fieldedTableNew(reportFileName, fields, fieldCount); while (lineFileRowTab(lf, fields)) { fieldedTableAdd(table, fields, fieldCount, lf->lineIx); } /* Clean up and go home. */ lineFileClose(&lf); return table; }