jl777 8 years ago
parent
commit
15840c7545
  1. 31
      iguana/iguana_ramchain.c

31
iguana/iguana_ramchain.c

@ -1994,10 +1994,10 @@ void iguana_blockdelete(struct iguana_info *coin,bits256 hash2,int32_t i)
if ( fname[0] != 0 ) if ( fname[0] != 0 )
{ {
OS_removefile(fname,0); OS_removefile(fname,0);
/*#ifndef WIN32 #ifndef WIN32
strcat(fname,".tmp"); strcat(fname,".tmp");
OS_removefile(fname,0); OS_removefile(fname,0);
#endif*/ #endif
} }
} }
@ -2082,7 +2082,7 @@ int32_t iguana_oldbundlefiles(struct iguana_info *coin,uint32_t *ipbits,void **p
void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,struct iguana_bundle *bp,int32_t bundlei,int32_t renameflag) void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,struct iguana_bundle *bp,int32_t bundlei,int32_t renameflag)
{ {
int32_t checki,hdrsi; void *ptr = 0; FILE *fp; char renamed[1024]; static const bits256 zero; int32_t checki,hdrsi; long checksize; void *ptr = 0; FILE *fp; static const bits256 zero; char renamed[1024];
*filesizep = 0; *filesizep = 0;
fname[0] = 0; fname[0] = 0;
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,bp->hashes[bundlei],zero,1,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize ) if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,bp->hashes[bundlei],zero,1,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
@ -2094,22 +2094,41 @@ void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,str
return(0); return(0);
else else
{ {
fseek(fp,0,SEEK_END);
checksize = ftell(fp);
fclose(fp); fclose(fp);
/*#ifndef WIN32 #ifndef WIN32
if ( renameflag != 0 ) if ( renameflag != 0 )
{ {
sprintf(renamed,"%s.tmp",fname); sprintf(renamed,"%s.tmp",fname);
OS_renamefile(fname,renamed); OS_renamefile(fname,renamed);
strcpy(fname,renamed); strcpy(fname,renamed);
} }
#endif*/ #endif
if ( (ptr= OS_mapfile(fname,filesizep,0)) == 0 )
{
printf("error mapping.(%s) bundlei.%d\n",fname,bundlei);
return(0);
}
if ( *filesizep != checksize )
{
printf("%s *filesizep %ld != %ld\n",fname,*filesizep,checksize);
OS_releasemap(ptr,*filesizep);
sleep(1);
if ( (ptr= OS_mapfile(fname,filesizep,0)) == 0 ) if ( (ptr= OS_mapfile(fname,filesizep,0)) == 0 )
{ {
printf("error mapping.(%s) bundlei.%d\n",fname,bundlei); printf("error mapping.(%s) bundlei.%d\n",fname,bundlei);
return(0); return(0);
} }
if ( *filesizep != checksize )
{
printf("second %s failure *filesizep %ld != %ld\n",fname,*filesizep,checksize);
OS_releasemap(ptr,*filesizep);
return(0);
}
}
} }
printf("mapped.(%s) bundlei.[%d:%d] %p[%ld]\n",fname,hdrsi,bundlei,ptr,*filesizep); //printf("mapped.(%s) bundlei.[%d:%d] %p[%ld]\n",fname,hdrsi,bundlei,ptr,*filesizep);
return(ptr); return(ptr);
} }

Loading…
Cancel
Save