IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17494


Ignore:
Timestamp:
Apr 30, 2008, 11:04:22 AM (18 years ago)
Author:
eugene
Message:

mods for UPDATE / REPLACE options

Location:
branches/eam_branch_20080430/psLib/src/types
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080430/psLib/src/types/psMetadata.c

    r16814 r17494  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.168 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2008-03-05 00:57:00 $
     14 *  @version $Revision: 1.168.6.1 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2008-04-30 21:04:22 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    495495    bool result = true;
    496496
     497    // we loop over the metadata container by item, not by name.  this pushes us directly into
     498    // the elements of the MULTI items; we miss the containers.  We need to check the
     499    // (possible) MULTI containers to see how to set the flags.  If we encounter a MULTI which
     500    // is requesting REPLACE, then the first item on the input list from that MULTI should be
     501    // added with the REPLACE flag turned on; the rest should have the REPLACE flag turned off.
     502    // save a list of the MULTI entries which has REPLACE turned off?
     503
     504    psArray *multiItems = psArrayAlloc (128);
     505
    497506    psMetadataIterator *iter = psMetadataIteratorAlloc(in, PS_LIST_HEAD, NULL);
    498507    psMetadataItem *inItem = NULL;
    499508    while ((inItem = psMetadataGetAndIncrement(iter))) {
     509
     510        // it is not possible to have RESET && UPDATE
     511        // is it possible to have !RESET && !UPDATE?
     512        // are these mutually exclusive conditions?
     513        // input MULTI & RESET  : replace an existing MULTI or ITEM of same name
     514        // input MULTI & UPDATE : supplement an existing MULTI or ITEM of same name
     515        // in both cases the name must exist in 'out'
     516
    500517        // Need to look for MULTI, which won't be picked up using the iterator.
    501518        psMetadataItem *multiCheckItem = psMetadataLookup(in, inItem->name);
    502         unsigned int flag = PS_META_REPLACE | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE; // Flag to indicate MULTI; otherwise, replace
    503         if (multiCheckItem->type == PS_DATA_METADATA_MULTI) {
    504             psTrace("psLib.types", 10, "MULTI: %s (%s)\n", inItem->name, inItem->comment);
    505             flag = PS_META_DUPLICATE_OK | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;
     519
     520        // default operation for the new metadata item (replace existing entry, require existence & type)
     521        unsigned int flag = PS_META_REPLACE | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;
     522
     523        // for MULTI items, the mode is carried on the multi container
     524        if (PS_METADATA_ITEM_GET_TYPE(multiCheckItem) == PS_DATA_METADATA_MULTI) {
     525            psTrace("psLib.types", 10, "MULTI: %s (%s)\n", inItem->name, inItem->comment);
     526            if (multiCheckItem->type & PS_META_UPDATE_FOLDER) {
     527                psTrace("psLib.types", 10, "supplement MULTI with new entries\n");
     528                flag = PS_META_DUPLICATE_OK | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;
     529            } else {
     530                multiCheckItem->type |= PS_META_UPDATE_FOLDER;
     531                // save this multi so we can reset their flags below
     532                psArrayAdd (multiItems, 128, multiCheckItem);
     533            }
    506534        }
    507535        psTrace("psLib.types", 5, "Copying %s (%s)...\n", inItem->name, inItem->comment);
     536
     537        // for METADATA folders, do something different?
     538        if (PS_METADATA_ITEM_GET_TYPE(inItem) == PS_DATA_METADATA) {
     539            if (inItem->type & PS_META_UPDATE_FOLDER) {
     540                flag = PS_META_UPDATE_FOLDER | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;
     541            }
     542        }
    508543
    509544        // Copy the item and add it on.  report all errors so we get a listing
     
    517552    psFree(iter);
    518553
     554    // remove the UPDATE_FOLDER flag from the following MULTI items
     555    for (int i = 0; i < multiItems->n; i++) {
     556        psMetadataItem *item = multiItems->data[i];
     557        item->type &= ~PS_META_UPDATE_FOLDER;
     558    }
     559    psFree (multiItems);
     560
    519561    if (!result) {
    520562        psError(PS_ERR_UNKNOWN, false, "failed to update metadata\n");
    521563    }
     564
    522565    return result;
    523566}
  • branches/eam_branch_20080430/psLib/src/types/psMetadata.h

    r14452 r17494  
    99*  @author Ross Harman, MHPCC
    1010*
    11 *  @version $Revision: 1.103 $ $Name: not supported by cvs2svn $
    12 *  @date $Date: 2007-08-09 01:40:08 $
     11*  @version $Revision: 1.103.12.1 $ $Name: not supported by cvs2svn $
     12*  @date $Date: 2008-04-30 21:04:22 $
    1313*
    1414*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5757 */
    5858typedef enum {
    59     PS_META_DEFAULT = 0,               ///< default behaviour (duplicate entry is an error)
    60     PS_META_REPLACE = 0x1000000,       ///< allow entry to be replaced
    61     PS_META_NO_REPLACE = 0x2000000,    ///< duplicate entry is silently skipped
    62     PS_META_DUPLICATE_OK = 0x4000000,  ///< allow duplicate entries
    63     PS_META_NULL = 0x8000000,           ///< psMetadataItem.data is a NULL value
    64     PS_META_REQUIRE_ENTRY = 0x10000000, ///< require pre-existing entry with same name
    65     PS_META_REQUIRE_TYPE = 0x20000000   ///< require pre-existing entry to have same type
     59    PS_META_DEFAULT       = 0,          ///< default behaviour (duplicate entry is an error)
     60    PS_META_REPLACE       = 0x01000000, ///< allow entry to be replaced
     61    PS_META_NO_REPLACE    = 0x02000000, ///< duplicate entry is silently skipped
     62    PS_META_DUPLICATE_OK  = 0x04000000, ///< allow duplicate entries
     63    PS_META_UPDATE_FOLDER = 0x08000000, ///< for a metadata folder, merge contents with existing md
     64    PS_META_NULL          = 0x10000000, ///< psMetadataItem.data is a NULL value
     65    PS_META_REQUIRE_ENTRY = 0x20000000, ///< require pre-existing entry with same name
     66    PS_META_REQUIRE_TYPE  = 0x40000000  ///< require pre-existing entry to have same type
    6667} psMetadataFlags;
    6768
     
    6970#define PS_METADATA_TYPE_MASK 0x00FFFFFF
    7071
     72#define PS_METADATA_ITEM_TYPE(ITEM) (MD->type & PS_METADATA_TYPE_MASK)
    7173
    7274/** Metadata data structure.
  • branches/eam_branch_20080430/psLib/src/types/psMetadataConfig.c

    r15505 r17494  
    1111*  @author Joshua Hoblitt, University of Hawaii 2006-2007
    1212*
    13 *  @version $Revision: 1.142 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2007-11-08 04:24:01 $
     13*  @version $Revision: 1.142.8.1 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2008-04-30 21:04:22 $
    1515*
    1616*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    802802    }
    803803
    804     // If type is not MULTI or META then get the value and comment
    805     if((mdType != PS_DATA_METADATA_MULTI) && (mdType != PS_DATA_METADATA)) {
     804    // If type is MULTI or META then check for the (optional) directives UPDATE or RESET;
     805    // otherwise, get the value and comment.
     806    if((mdType == PS_DATA_METADATA_MULTI) || (mdType == PS_DATA_METADATA)) {
     807        // Get the metadata item value if there is one.
     808        status = 0;
     809        strValue = getToken (&linePtr, "#", &status, true);
     810
     811        if (status) {
     812            psError(PS_ERR_IO, true, _("Failed to examine line for optional directive."));
     813            psFree(strType);
     814            psFree(strValue);
     815            return false;
     816        }
     817
     818        if (strValue) {
     819            // found a directive, what does it say?
     820            if (strcasecmp (strValue, "UPDATE") && strcasecmp (strValue, "UPDATE")) {
     821                psError(PS_ERR_IO, true, _("Invalid directive %s for METADATA or MULTI.", strValue));
     822                psFree(strType);
     823                psFree(strValue);
     824                return false;
     825            }
     826
     827            // found a directive, what does it say?
     828            if (!strcasecmp (strValue, "UPDATE")) {
     829                // this folder or group is merged with an existing one of the same name
     830                flags |= PS_META_UPDATE_FOLDER;
     831            }
     832            if (!strcasecmp (strValue, "RESET")) {
     833                // this folder or group replaces an existing one of the same name
     834                flags |= PS_META_REPLACE;
     835            }
     836        }
     837        psFree(strValue);
     838        strValue = NULL;
     839
     840        // Not all lines will have comments, so NULL is ok.
     841        status = 0;
     842
     843        // XXX this is a very ugly way of finding from the current position to
     844        // the end of the line
     845        strComment = getToken(&linePtr, "", &status, true);
     846
     847        if (status) {
     848            psError(PS_ERR_IO, true, _("Error reading a metadata comment"));
     849            psFree(strType);
     850            psFree(strComment);
     851            return false;
     852        }
     853    } else {
    806854        // Get the metadata item value if there is one.
    807855        status = 0;
     
    833881            return false;
    834882        }
    835     }
     883    } 
    836884
    837885#define PARSE_ADD_CASE(NAME, TYPE, PARSEFUNC) \
Note: See TracChangeset for help on using the changeset viewer.