Updates in mbfile for new experimental fdb code
This commit is contained in:
parent
fa460d8597
commit
c5d419c88d
@ -46,9 +46,14 @@ extern int do_quiet; /* Suppress screen output */
|
|||||||
*/
|
*/
|
||||||
void Delete(int UnDel, int Area, char *File)
|
void Delete(int UnDel, int Area, char *File)
|
||||||
{
|
{
|
||||||
char *temp, mask[256];
|
char mask[256];
|
||||||
FILE *fp;
|
|
||||||
int rc = FALSE;
|
int rc = FALSE;
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
struct _fdbarea *fdb_area = NULL;
|
||||||
|
#else
|
||||||
|
FILE *fp;
|
||||||
|
char *temp;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (UnDel)
|
if (UnDel)
|
||||||
IsDoing("Undelete file");
|
IsDoing("Undelete file");
|
||||||
@ -75,6 +80,12 @@ void Delete(int UnDel, int Area, char *File)
|
|||||||
printf("Can't %sdelete from CD-ROM\n", UnDel?"un":"");
|
printf("Can't %sdelete from CD-ROM\n", UnDel?"un":"");
|
||||||
die(MBERR_COMMANDLINE);
|
die(MBERR_COMMANDLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
if ((fdb_area = mbsedb_OpenFDB(Area, 30)) == NULL)
|
||||||
|
die(MBERR_GENERAL);
|
||||||
|
|
||||||
|
#else
|
||||||
if (CheckFDB(Area, area.Path))
|
if (CheckFDB(Area, area.Path))
|
||||||
die(MBERR_GENERAL);
|
die(MBERR_GENERAL);
|
||||||
|
|
||||||
@ -85,12 +96,18 @@ void Delete(int UnDel, int Area, char *File)
|
|||||||
die(MBERR_GENERAL);
|
die(MBERR_GENERAL);
|
||||||
|
|
||||||
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
||||||
|
#endif
|
||||||
|
|
||||||
colour(CYAN, BLACK);
|
colour(CYAN, BLACK);
|
||||||
strcpy(mask, re_mask(File, FALSE));
|
strcpy(mask, re_mask(File, FALSE));
|
||||||
if (re_comp(mask))
|
if (re_comp(mask))
|
||||||
die(MBERR_GENERAL);
|
die(MBERR_GENERAL);
|
||||||
|
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
|
||||||
|
#else
|
||||||
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1) {
|
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1) {
|
||||||
|
#endif
|
||||||
if (re_exec(fdb.LName) || re_exec(fdb.Name)) {
|
if (re_exec(fdb.LName) || re_exec(fdb.Name)) {
|
||||||
if (UnDel && fdb.Deleted) {
|
if (UnDel && fdb.Deleted) {
|
||||||
fdb.Deleted = FALSE;
|
fdb.Deleted = FALSE;
|
||||||
@ -107,20 +124,33 @@ void Delete(int UnDel, int Area, char *File)
|
|||||||
rc = TRUE;
|
rc = TRUE;
|
||||||
}
|
}
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
if (mbsedb_LockFDB(fdb_area, 30)) {
|
||||||
|
fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR);
|
||||||
|
fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
|
||||||
|
mbsedb_UnlockFDB(fdb_area);
|
||||||
|
} else {
|
||||||
|
rc = FALSE;
|
||||||
|
}
|
||||||
|
#else
|
||||||
fseek(fp, - fdbhdr.recsize, SEEK_CUR);
|
fseek(fp, - fdbhdr.recsize, SEEK_CUR);
|
||||||
fwrite(&fdb, fdbhdr.recsize, 1, fp);
|
fwrite(&fdb, fdbhdr.recsize, 1, fp);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
mbsedb_CloseFDB(fdb_area);
|
||||||
|
#else
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
free(temp);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
Syslog('+', "%selete %s in area %d failed", UnDel?"Und":"D", File, Area);
|
Syslog('+', "%selete %s in area %d failed", UnDel?"Und":"D", File, Area);
|
||||||
if (!do_quiet)
|
if (!do_quiet)
|
||||||
printf("%selete %s in area %d failed\n", UnDel?"Und":"D", File, Area);
|
printf("%selete %s in area %d failed\n", UnDel?"Und":"D", File, Area);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(temp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -316,14 +316,22 @@ void closepage(FILE *fa, char *Path, int inArea, int Current, FILE *fi)
|
|||||||
void ReqIndex(void);
|
void ReqIndex(void);
|
||||||
void ReqIndex(void)
|
void ReqIndex(void)
|
||||||
{
|
{
|
||||||
FILE *pAreas, *pFile, *pIndex, *fp;
|
FILE *pAreas, *pIndex, *fp;
|
||||||
unsigned long i, iAreas, iAreasNew = 0, record;
|
unsigned long i, iAreas, iAreasNew = 0, record;
|
||||||
int iTotal = 0, j, z, x = 0;
|
int iTotal = 0, j, z, x = 0;
|
||||||
int fbAreas = 0, fbFiles = 0;
|
int fbAreas = 0, fbFiles = 0;
|
||||||
char *sAreas, *fAreas, *newdir = NULL, *sIndex, *temp;
|
char *sAreas, *newdir = NULL, *sIndex, *temp;
|
||||||
Findex *fdx = NULL;
|
Findex *fdx = NULL;
|
||||||
Findex *tmp;
|
Findex *tmp;
|
||||||
struct FILEIndex idx;
|
struct FILEIndex idx;
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
struct _fdbarea *fdb_area = NULL;
|
||||||
|
#else
|
||||||
|
FILE *pFile;
|
||||||
|
char *fAreas;
|
||||||
|
|
||||||
|
fAreas = calloc(PATH_MAX, sizeof(char));
|
||||||
|
#endif
|
||||||
|
|
||||||
IsDoing("Index files");
|
IsDoing("Index files");
|
||||||
if (!do_quiet) {
|
if (!do_quiet) {
|
||||||
@ -332,7 +340,6 @@ void ReqIndex(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sAreas = calloc(PATH_MAX, sizeof(char));
|
sAreas = calloc(PATH_MAX, sizeof(char));
|
||||||
fAreas = calloc(PATH_MAX, sizeof(char));
|
|
||||||
sIndex = calloc(PATH_MAX, sizeof(char));
|
sIndex = calloc(PATH_MAX, sizeof(char));
|
||||||
temp = calloc(PATH_MAX, sizeof(char));
|
temp = calloc(PATH_MAX, sizeof(char));
|
||||||
|
|
||||||
@ -379,6 +386,10 @@ void ReqIndex(void)
|
|||||||
newdir = NULL;
|
newdir = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
if ((fdb_area = mbsedb_OpenFDB(i, 30)) == NULL)
|
||||||
|
die(MBERR_GENERAL);
|
||||||
|
#else
|
||||||
sprintf(fAreas, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), i);
|
sprintf(fAreas, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), i);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -397,6 +408,7 @@ void ReqIndex(void)
|
|||||||
} else {
|
} else {
|
||||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create file request index if requests are allowed in this area.
|
* Create file request index if requests are allowed in this area.
|
||||||
@ -406,7 +418,11 @@ void ReqIndex(void)
|
|||||||
* Now start creating the unsorted index.
|
* Now start creating the unsorted index.
|
||||||
*/
|
*/
|
||||||
record = 0;
|
record = 0;
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
|
||||||
|
#else
|
||||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||||
|
#endif
|
||||||
iTotal++;
|
iTotal++;
|
||||||
if ((iTotal % 10) == 0)
|
if ((iTotal % 10) == 0)
|
||||||
Marker();
|
Marker();
|
||||||
@ -431,9 +447,14 @@ void ReqIndex(void)
|
|||||||
if ((fp = fopen(temp, "w")) == NULL) {
|
if ((fp = fopen(temp, "w")) == NULL) {
|
||||||
WriteError("$Can't create %s", temp);
|
WriteError("$Can't create %s", temp);
|
||||||
} else {
|
} else {
|
||||||
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
|
||||||
fbAreas++;
|
fbAreas++;
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET);
|
||||||
|
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
|
||||||
|
#else
|
||||||
|
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
||||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||||
|
#endif
|
||||||
if (!fdb.Deleted) {
|
if (!fdb.Deleted) {
|
||||||
fbFiles++;
|
fbFiles++;
|
||||||
fprintf(fp, "%-12s [%ld] %s\r\n", fdb.Name, fdb.TimesDL, fdb.Desc[0]);
|
fprintf(fp, "%-12s [%ld] %s\r\n", fdb.Name, fdb.TimesDL, fdb.Desc[0]);
|
||||||
@ -455,9 +476,13 @@ void ReqIndex(void)
|
|||||||
if ((fp = fopen(temp, "w")) == NULL) {
|
if ((fp = fopen(temp, "w")) == NULL) {
|
||||||
WriteError("$Can't create %s", temp);
|
WriteError("$Can't create %s", temp);
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET);
|
||||||
|
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
|
||||||
|
#else
|
||||||
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
||||||
|
|
||||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||||
|
#endif
|
||||||
if (!fdb.Deleted) {
|
if (!fdb.Deleted) {
|
||||||
/*
|
/*
|
||||||
* The next is to reduce system load
|
* The next is to reduce system load
|
||||||
@ -485,8 +510,13 @@ void ReqIndex(void)
|
|||||||
chmod(temp, 0644);
|
chmod(temp, 0644);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
mbsedb_CloseFDB(fdb_area);
|
||||||
|
#else
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
}
|
free(fAreas);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(pAreas);
|
fclose(pAreas);
|
||||||
@ -501,7 +531,6 @@ void ReqIndex(void)
|
|||||||
Syslog('+', "Files Areas [%5d] Files [%5d]", fbAreas, fbFiles);
|
Syslog('+', "Files Areas [%5d] Files [%5d]", fbAreas, fbFiles);
|
||||||
|
|
||||||
free(sAreas);
|
free(sAreas);
|
||||||
free(fAreas);
|
|
||||||
free(sIndex);
|
free(sIndex);
|
||||||
free(temp);
|
free(temp);
|
||||||
}
|
}
|
||||||
@ -515,17 +544,23 @@ void ReqIndex(void)
|
|||||||
void HtmlIndex(char *);
|
void HtmlIndex(char *);
|
||||||
void HtmlIndex(char *Lang)
|
void HtmlIndex(char *Lang)
|
||||||
{
|
{
|
||||||
FILE *pAreas, *pFile, *fa, *fb = NULL, *fm, *fi = NULL;
|
FILE *pAreas, *fa, *fb = NULL, *fm, *fi = NULL;
|
||||||
unsigned long i, iAreas, KSize = 0L, aSize = 0;
|
unsigned long i, iAreas, KSize = 0L, aSize = 0;
|
||||||
int AreaNr = 0, j, k, x = 0;
|
int AreaNr = 0, j, k, x = 0;
|
||||||
int aTotal = 0, inArea = 0, filenr;
|
int aTotal = 0, inArea = 0, filenr;
|
||||||
char *sAreas, *fAreas, *fn;
|
char *sAreas, *fn;
|
||||||
char linebuf[1024], outbuf[1024], desc[6400];
|
char linebuf[1024], outbuf[1024], desc[6400];
|
||||||
time_t last = 0L, later;
|
time_t last = 0L, later;
|
||||||
long fileptr = 0, fileptr1 = 0;
|
long fileptr = 0, fileptr1 = 0;
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
struct _fdbarea *fdb_area = NULL;
|
||||||
|
#else
|
||||||
|
FILE *pFile;
|
||||||
|
char *fAreas;
|
||||||
|
|
||||||
sAreas = calloc(PATH_MAX, sizeof(char));
|
|
||||||
fAreas = calloc(PATH_MAX, sizeof(char));
|
fAreas = calloc(PATH_MAX, sizeof(char));
|
||||||
|
#endif
|
||||||
|
sAreas = calloc(PATH_MAX, sizeof(char));
|
||||||
fn = calloc(PATH_MAX, sizeof(char));
|
fn = calloc(PATH_MAX, sizeof(char));
|
||||||
|
|
||||||
AreasHtml = 0;
|
AreasHtml = 0;
|
||||||
@ -605,6 +640,10 @@ void HtmlIndex(char *Lang)
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
if ((fdb_area = mbsedb_OpenFDB(i, 30)) == NULL)
|
||||||
|
die(MBERR_GENERAL);
|
||||||
|
#else
|
||||||
sprintf(fAreas, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), i);
|
sprintf(fAreas, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), i);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -616,21 +655,33 @@ void HtmlIndex(char *Lang)
|
|||||||
die(MBERR_GENERAL);
|
die(MBERR_GENERAL);
|
||||||
}
|
}
|
||||||
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
fread(&fdbhdr, sizeof(fdbhdr), 1, pFile);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create index.html pages in each available download area.
|
* Create index.html pages in each available download area.
|
||||||
*/
|
*/
|
||||||
if (!area.CDrom && fm && (strncmp(CFG.ftp_base, area.Path, strlen(CFG.ftp_base)) == 0)) {
|
if (!area.CDrom && fm && (strncmp(CFG.ftp_base, area.Path, strlen(CFG.ftp_base)) == 0)) {
|
||||||
|
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET);
|
||||||
|
#else
|
||||||
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
||||||
|
#endif
|
||||||
AreasHtml++;
|
AreasHtml++;
|
||||||
inArea = 0;
|
inArea = 0;
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
|
||||||
|
#else
|
||||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||||
|
#endif
|
||||||
if (!fdb.Deleted)
|
if (!fdb.Deleted)
|
||||||
inArea++;
|
inArea++;
|
||||||
}
|
}
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET);
|
||||||
|
#else
|
||||||
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
||||||
|
#endif
|
||||||
aSize = 0L;
|
aSize = 0L;
|
||||||
aTotal = 0;
|
aTotal = 0;
|
||||||
last = 0L;
|
last = 0L;
|
||||||
@ -641,7 +692,11 @@ void HtmlIndex(char *Lang)
|
|||||||
fileptr1 = gfilepos;
|
fileptr1 = gfilepos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
|
||||||
|
#else
|
||||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||||
|
#endif
|
||||||
if (!fdb.Deleted) {
|
if (!fdb.Deleted) {
|
||||||
/*
|
/*
|
||||||
* The next is to reduce system load
|
* The next is to reduce system load
|
||||||
@ -750,8 +805,12 @@ void HtmlIndex(char *Lang)
|
|||||||
fseek(fi, fileptr, SEEK_SET);
|
fseek(fi, fileptr, SEEK_SET);
|
||||||
MacroRead(fi, fm);
|
MacroRead(fi, fm);
|
||||||
}
|
}
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
mbsedb_CloseFDB(fdb_area);
|
||||||
|
#else
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
|
free(fAreas);
|
||||||
|
#endif
|
||||||
} /* if area.Available */
|
} /* if area.Available */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -775,7 +834,6 @@ void HtmlIndex(char *Lang)
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(sAreas);
|
free(sAreas);
|
||||||
free(fAreas);
|
|
||||||
free(fn);
|
free(fn);
|
||||||
RemoveSema((char *)"reqindex");
|
RemoveSema((char *)"reqindex");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user