IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 17, 2009, 10:12:18 AM (17 years ago)
Author:
Paul Price
Message:

Some fixes required for pantasks operation: needed '-limit' for the list mode, need to check if a fileset exists before inserting it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/receivetool.c

    r23894 r23898  
    122122    PXOPT_COPY_S64(config->args, where, "-comment", "receiveSource.comment", "LIKE");
    123123
     124    // optional
     125    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     126    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     127
    124128    psString query = pxDataGet("receivetool_list.sql");
    125129    if (!query) {
     
    136140    psFree(where);
    137141
     142    if (limit) {
     143        psString limitString = psDBGenerateLimitSQL(limit);
     144        psStringAppend(&query, " %s", limitString);
     145        psFree(limitString);
     146    }
     147
    138148    if (!p_psDBRunQueryF(config->dbh, query)) {
    139149        psError(PS_ERR_UNKNOWN, false, "Database error");
     
    153163        return true;
    154164    }
    155     if (!ippdbPrintMetadatas(stdout, output, "receiveSource", true)) {
     165    if (!ippdbPrintMetadatas(stdout, output, "receiveSource", !simple)) {
    156166        psError(PS_ERR_UNKNOWN, false, "Failed to print array");
    157167        psFree(output);
     
    175185    }
    176186
     187    psString query = pxDataGet("receivetool_addfileset.sql");
     188    if (!query) {
     189        psError(PXTOOLS_ERR_DATA, false, "Failed to retreive SQL statement");
     190        return false;
     191    }
     192
    177193    if (!psDBTransaction(config->dbh)) {
    178194        psError(PS_ERR_UNKNOWN, false, "Database error");
    179195        return false;
    180196    }
     197
     198    psString source_id_str = NULL;      // source_id as a string
     199    psStringAppend(&source_id_str, "%" PRId64, source_id);
    181200
    182201    psListIterator *iter = psListIteratorAlloc(filesets->data.list, PS_LIST_HEAD, false); // Iterator
     
    184203    while ((item = psListGetAndIncrement(iter))) {
    185204        psAssert(item && item->data.V && item->type == PS_DATA_STRING, "Argument is bad");
    186 
    187         if (!receiveFilesetInsert(config->dbh, 0, source_id, item->data.str)) {
    188             psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
     205        const char *fileset = item->data.str; // Fileset name
     206
     207        if (!p_psDBRunQueryF(config->dbh, query, source_id_str, fileset)) {
     208            psError(PS_ERR_UNKNOWN, false, "Database error");
     209            psFree(source_id_str);
     210            psFree(query);
     211            psFree(iter);
    189212            if (!psDBTransaction(config->dbh)) {
    190213                psError(PS_ERR_UNKNOWN, false, "Database error");
    191                 return false;
    192214            }
     215            return false;
     216        }
     217
     218        psArray *output = p_psDBFetchResult(config->dbh); // Output of query
     219        if (!output) {
     220            psError(PS_ERR_UNKNOWN, false, "Database error");
     221            psFree(source_id_str);
     222            psFree(query);
    193223            psFree(iter);
    194224            return false;
    195225        }
     226        if (psArrayLength(output) > 0) {
     227            psTrace("receivetool", PS_LOG_INFO, "Fileset %s is already present", fileset);
     228            psFree(output);
     229            continue;
     230        }
     231        psFree(output);
     232
     233        if (!receiveFilesetInsert(config->dbh, 0, source_id, fileset)) {
     234            psError(PS_ERR_UNKNOWN, false, "Unable to add fileset");
     235            psFree(source_id_str);
     236            psFree(query);
     237            psFree(iter);
     238            if (!psDBTransaction(config->dbh)) {
     239                psError(PS_ERR_UNKNOWN, false, "Database error");
     240            }
     241            return false;
     242        }
    196243    }
    197244    psFree(iter);
     245    psFree(query);
     246    psFree(source_id_str);
    198247
    199248    if (!psDBCommit(config->dbh)) {
Note: See TracChangeset for help on using the changeset viewer.