IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4461


Ignore:
Timestamp:
Jul 5, 2005, 6:14:41 PM (21 years ago)
Author:
jhoblitt
Message:

add nebNukeFile()
fix some warnings
fix some formatting issues
fill in nebCull()
change nebDeleteInstance() to return bool
fill in nebDeleteInstance() src

File:
1 edited

Legend:

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

    r4456 r4461  
    44 * Copyright (C) 2005  Joshua Hoblitt
    55 *
    6  * $Id: nebclient.c,v 1.5 2005-07-06 02:44:12 jhoblitt Exp $
     6 * $Id: nebclient.c,v 1.6 2005-07-06 04:14:41 jhoblitt Exp $
    77 */
    88
     
    1515#include <string.h>
    1616#include <regex.h>
     17#include <unistd.h>
     18#include <stdbool.h>
    1719#include "xmalloc.h"
    1820#include "soapH.h"
     
    2527static off_t nebCopyFilehandle(int sourceFH, int destFH);
    2628static int nebParseURI(const char *URI, char **filename);
     29static bool nebNukeFile(const char *filename);
    2730
    2831void nebServerInit(nebServer *server)
     
    5861    int             file;
    5962
    60     if (soap_call_ns1__create_USCOREobject(server, NULL, NULL, key, class, volume, comment, &response) == SOAP_OK) {
    61         *URI = xmalloc(strlen(response.result));
    62         strcpy(*URI, response.result);
     63    if (soap_call_ns1__create_USCOREobject(server, NULL, NULL, key, class, volume, comment, (char **)&response) == SOAP_OK) {
     64        *URI = xmalloc(strlen((char *)response.result));
     65        strcpy(*URI, (char *)response.result);
    6366
    6467        if (!nebParseURI(*URI, &filename)) {
     
    8891    int             sourceFH, destFH;
    8992
    90     if (soap_call_ns1__replicate_USCOREobject(server, NULL, NULL, key, volume, &response) == SOAP_OK) {
    91         *URI = xmalloc(strlen(response.result));
    92         strcpy(*URI, response.result);
     93    if (soap_call_ns1__replicate_USCOREobject(server, NULL, NULL, key, volume, (char **)&response) == SOAP_OK) {
     94        *URI = xmalloc(strlen((char *)response.result));
     95        strcpy(*URI, (char *)response.result);
    9396
    9497        if (!nebParseURI(*URI, &filename)) {
     
    131134}
    132135
    133 int nebCull( nebServer *server,char *key )
    134 {
    135 
    136     return 0;
     136int nebCull(nebServer *server, char *key)
     137{
     138    char            **locations;
     139    int             n;
     140
     141    n = nebFindInstances(server, key, NULL, &locations);
     142
     143    printf( "found %d instances\n", n );
     144
     145    if (n < 2 ) {
     146        fprintf(stderr, "can not cull - not enough instances");
     147        //free locations
     148        return -1;
     149    }
     150
     151    return nebDeleteInstance(server, locations[0]);
    137152}
    138153
     
    210225}
    211226
    212 int nebDelete_instance(nebServer *server, char *URI )
    213 {
    214 
    215     return 0;
     227bool nebDeleteInstance(nebServer *server, const char *URI)
     228{
     229    int             *response;
     230    char            *filename;
     231    bool            status;
     232
     233    if (!nebParseURI(URI, &filename)) {
     234        fprintf(stderr, "can not parse URI\n");
     235
     236        return false;
     237    }
     238
     239    if (soap_call_ns1__delete_USCOREinstance(server, NULL, NULL, (char *)URI, response) != SOAP_OK) {
     240        nebFree(filename);
     241
     242        return false;
     243    }
     244
     245    if (*response > 0) {
     246        status = nebNukeFile(filename);
     247    } else {
     248        status = false;
     249    }
     250
     251    nebFree(filename);
     252
     253    return status;
    216254}
    217255
     
    364402    return bytesTotal;
    365403}
     404
     405static bool nebNukeFile(const char *filename)
     406{
     407    if (unlink(filename) < 0) {
     408        perror("unlink");
     409
     410        return false;
     411    }
     412             
     413    return true;
     414}
Note: See TracChangeset for help on using the changeset viewer.