IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24939


Ignore:
Timestamp:
Jul 29, 2009, 11:30:24 AM (17 years ago)
Author:
jhoblitt
Message:

add nebObjectStatFree()
flesh out nebThereCanBeOnlyOne()

Location:
trunk/Nebulous/nebclient
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/nebclient/src/nebclient.c

    r24931 r24939  
    833833}
    834834
     835void nebObjectStatFree(nebObjectStat *stat)
     836{
     837    if (!stat) {
     838        return;
     839    }
     840
     841    xfree(stat->so_id);
     842    xfree(stat->ext_id);
     843    xfree(stat->read_lock);
     844    xfree(stat->write_lock);
     845    xfree(stat->epoch);
     846    xfree(stat->mtime);
     847    xfree(stat);
     848}
     849
    835850
    836851int nebChmod(nebServer *server, const char *key, mode_t mode)
    837852{
    838     int response;
    839 
    840853    REQUIRE_SERVER;
    841854
     
    849862    // manual seems to 'suggest' that this is temporary data that gets cleaed
    850863    // up on the next soap function call
     864    int response;
    851865    if (soap_call_ns1__chmod_USCOREobject(server->soap, server->endpoint,
    852866            NULL, (char *)key, mode, &response) != SOAP_OK) {
     
    861875int nebPrune(nebServer *server, const char *key)
    862876{
    863     int response;
    864 
    865877    REQUIRE_SERVER;
    866878
     
    874886    // manual seems to 'suggest' that this is temporary data that gets cleaed
    875887    // up on the next soap function call
     888    int response;
    876889    if (soap_call_ns1__prune_USCOREobject(server->soap, server->endpoint,
    877890            NULL, (char *)key, &response) != SOAP_OK) {
     
    893906    }
    894907
     908    // first - strip off any inaccesible instances
    895909    if (nebPrune(server, key) < 0 ) {
    896     }
    897 
     910        // use the prune() method to also determine if $key is valid
     911        return -1;
     912    }
     913
     914    // check to see if there is an instance on $vol_name that should be the
     915    // sole survivor
    898916    nebObjectInstances *locations = NULL;
    899917    if (volume) {
     
    901919    }
    902920
     921    long removed = 0;
    903922    if (locations && locations->n) {
    904923        nebObjectInstances *instances = nebFindInstances(server, key, NULL);
    905924        for (long i = 0; i < instances->n; i++) {
    906             if (strcmp(locations->URI[0], instances->URI[i])) {
    907                 nebDeleteInstance(server, key, instances->URI[i]);
     925            if (strcmp(locations->URI[0], instances->URI[i]) == 0) {
     926                continue;
    908927            }
     928            if (!nebDeleteInstance(server, key, instances->URI[i])) {
     929                nebObjectInstancesFree(instances);
     930                nebObjectInstancesFree(locations);
     931                return -1;
     932            }
     933            removed++;
    909934        }
    910935        nebObjectInstancesFree(instances);
    911     }
    912     nebObjectInstancesFree(locations);
    913 
    914 
    915     return 0;
     936        nebObjectInstancesFree(locations);
     937    } else {
     938        // nuke whatever
     939        nebObjectStat *stat = nebStat(server, key);
     940        if (!stat) {
     941            return -1;
     942        }
     943        // start at one so cull() is called one less time then the # of
     944        // instances
     945        for (long i = 1; i < stat->available; i++) {
     946            if (!nebCull(server, key)) {
     947                nebObjectStatFree(stat);
     948                return -1;
     949            }
     950            removed++;
     951        }
     952        nebObjectStatFree(stat);
     953    }
     954
     955    return removed;
    916956}
    917957
  • trunk/Nebulous/nebclient/src/nebclient.h

    r24931 r24939  
    299299);
    300300
     301
     302/** Deallocates a stat object
     303 */
     304void nebObjectStatFree(
     305    nebObjectStat *stat                 ///< nebObjectStat object
     306);
     307
    301308/** Change permissions of a storage objects
    302309 *
  • trunk/Nebulous/nebclient/tests/tests.c

    r24923 r24939  
    2020    char            *key = "foobarbaz";
    2121
    22     plan_tests(30);
     22    plan_tests(31);
    2323
    2424    if (getenv("NEB_SERVER")) {
     
    141141    neb_ok(server, nebPrune(server, "movedfile") == 0, "prune object");
    142142
     143    nebReplicate(server, key, NULL, NULL);
     144    neb_ok(server, nebThereCanBeOnlyOne(server, "movedfile", NULL) == 0, "reduce instances to only 1");
     145
    143146    if (!nebDelete(server, "movedfile")) {
    144147        diag( "cleanup failed %s\n", nebErr(server));
Note: See TracChangeset for help on using the changeset viewer.