Changeset 292 for trunk/zoo-kernel


Ignore:
Timestamp:
Aug 3, 2011, 3:33:48 PM (13 years ago)
Author:
djay
Message:

Remove the list file and directly name zca files using the md5 of the URL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-kernel/service_internal.c

    r291 r292  
    23272327  map* tmp=getMapFromMaps(conf,"main","cacheDir");
    23282328  if(tmp!=NULL){
    2329     char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+6));
    2330     sprintf(fname,"%s/list",tmp->value);
     2329    unsigned char* md5str=getMd5(request);
     2330    char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
     2331    sprintf(fname,"%s/%s.zca",tmp->value,md5str);
    23312332#ifdef DEBUG
    23322333    fprintf(stderr,"Cache list : %s\n",fname);
     
    23352336    struct stat f_status;
    23362337    int s=stat(fname, &f_status);
    2337     /**
    2338      * If the file does not exist, create it
    2339      */
    2340     if(s<0){
    2341       FILE* f=fopen(fname,"w+");
    2342       if(f)
    2343         fclose(f);
    2344       s=stat(fname, &f_status);
    2345     }
    2346     if(f_status.st_size>=0){
    2347       FILE* f=fopen(fname,"a+");
    2348       char* foname=(char*)malloc(sizeof(char)*65);
    2349       char* fonames=(char*)malloc(sizeof(char)*(strlen(tmp->value)+70));
    2350       sprintf(foname,"%d",f_status.st_size);
    2351       sprintf(fonames,"%s/%s.zca",tmp->value,foname);
    2352 #ifdef DEBUG
    2353       fprintf(stderr,"Cache file : %s\n",foname);
    2354       fflush(stderr);
    2355 #endif
    2356       FILE* fo=fopen(fonames,"w+");
    2357       char *fcontent=(char*)malloc(sizeof(char)*(strlen(foname)+strlen(request)+3));
    2358       unsigned char* md5str=getMd5(request);
    2359       sprintf(fcontent,"%s|%s\n",md5str,foname);
     2338    if(f_status.st_size>0){
     2339      FILE* fo=fopen(fname,"w+");
     2340      fwrite(content,sizeof(char),length,fo);
    23602341      free(md5str);
    2361       free(foname);
    2362       free(fonames);     
    2363       fwrite(fcontent,sizeof(char),strlen(fcontent),f);
    2364       fwrite(content,sizeof(char),length,fo);
    2365       fclose(f);
     2342      free(fname);
    23662343      fclose(fo);
    23672344    }
     
    23762353    fprintf(stderr,"MD5STR : (%s)\n\n",md5str);
    23772354#endif
    2378     char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+6));
    2379     sprintf(fname,"%s/list",tmpM->value);
     2355    char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+38));
     2356    sprintf(fname,"%s/%s.zca",tmpM->value,md5str);
    23802357    struct stat f_status;
    23812358    int s=stat(fname, &f_status);
    2382     if(s==0){
    2383       char* fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
    2384       FILE* f=fopen(fname,"r");
    2385       fread(fcontent,sizeof(char),f_status.st_size,f);
    2386       char *tmp,*svt;
    2387       tmp=strtok_r(fcontent,"\n",&svt);
    2388       int lin=0;
    2389       while(tmp!=NULL){
    2390         char *tmp1,*svt1;
    2391         tmp1=strtok_r(tmp,"|",&svt1);
    2392         int hv=-1;
    2393         while(tmp1!=NULL){
    2394           fprintf(stderr,"%s %s\n",tmp1,request);
    2395           if(hv>0){
    2396             char* foname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+68));
    2397             sprintf(foname,"%s/%s.zca",tmpM->value,tmp1);
    2398             free(md5str);
    2399             free(fname);
    2400             free(fcontent);
    2401 #ifdef DEBUG
    2402             fprintf(stderr,"Cache file : %s\n",foname);
    2403 #endif
    2404             return foname;
    2405           }
    2406           if(strcasecmp(tmp1,md5str)==0)
    2407             hv=1;
    2408           tmp1=strtok_r(NULL,"|",&svt1);
    2409         }
    2410         lin++;
    2411         tmp = strtok_r(NULL,"\n",&svt);
    2412       }
    2413       fclose(f);
    2414       free(fcontent);
    2415     }
     2359    if(s==0 && f_status.st_size>0){
     2360      free(md5str);
     2361      free(fname);
     2362      return fname;
     2363    }
    24162364    free(md5str);
    24172365    free(fname);
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png