Updates for new fdb code
This commit is contained in:
parent
75b991af56
commit
7aa6f678c2
19
lib/dbfdb.c
19
lib/dbfdb.c
@ -39,7 +39,7 @@
|
||||
|
||||
|
||||
/*
|
||||
* Open files database Area number, with path. Do some checks and abort
|
||||
* Open files database Area number. Do some checks and abort
|
||||
* if they fail.
|
||||
*/
|
||||
struct _fdbarea *mbsedb_OpenFDB(long Area, int Timeout)
|
||||
@ -68,12 +68,27 @@ struct _fdbarea *mbsedb_OpenFDB(long Area, int Timeout)
|
||||
msleep(250);
|
||||
Syslog('f', "Open file area %ld, try %d", Area, Tries);
|
||||
}
|
||||
if (fp == NULL) {
|
||||
if (errno == ENOENT) {
|
||||
Syslog('+', "Create empty FDB for area %ld", Area);
|
||||
fdbhdr.hdrsize = sizeof(fdbhdr);
|
||||
fdbhdr.recsize = sizeof(fdb);
|
||||
if ((fp = fopen(temp, "w+"))) {
|
||||
fwrite(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* If still not open, it's fatal.
|
||||
*/
|
||||
if (fp == NULL) {
|
||||
WriteError("$Can't open %s", temp);
|
||||
free(temp);
|
||||
return NULL;
|
||||
}
|
||||
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
||||
|
||||
/*
|
||||
* Fix attributes if needed
|
||||
|
@ -200,9 +200,8 @@ void Check(long AreaNr)
|
||||
|
||||
void CheckArea(long Area)
|
||||
{
|
||||
FILE *pFile;
|
||||
int j, Fix, inArea, rc;
|
||||
char *fAreas, *newdir, *temp, *mname, *tname;
|
||||
char *newdir, *temp, *mname, *tname;
|
||||
DIR *dp;
|
||||
struct dirent *de;
|
||||
int Found, Update;
|
||||
@ -210,8 +209,14 @@ void CheckArea(long Area)
|
||||
struct stat stb;
|
||||
struct passwd *pw;
|
||||
struct group *gr;
|
||||
#ifdef USE_EXPERIMENT
|
||||
struct _fdbarea *fdb_area = NULL;
|
||||
#else
|
||||
FILE *pFile;
|
||||
char *fAreas;
|
||||
|
||||
fAreas = calloc(PATH_MAX, sizeof(char));
|
||||
#endif
|
||||
newdir = calloc(PATH_MAX, sizeof(char));
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
mname = calloc(PATH_MAX, sizeof(char));
|
||||
@ -289,6 +294,10 @@ void CheckArea(long Area)
|
||||
WriteError("Can't stat %s", area.Path);
|
||||
}
|
||||
|
||||
#ifdef USE_EXPERIMENT
|
||||
if ((fdb_area = mbsedb_OpenFDB(Area, 30)) == NULL)
|
||||
return;
|
||||
#else
|
||||
sprintf(fAreas, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), Area);
|
||||
|
||||
/*
|
||||
@ -319,13 +328,18 @@ void CheckArea(long Area)
|
||||
Syslog('+', "fAreas recordsize is corrupt: %d, expected %d", fdbhdr.recsize, sizeof(fdbhdr));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Now start checking the files in the filedatabase
|
||||
* against the contents of the directory.
|
||||
*/
|
||||
inArea = 0;
|
||||
#ifdef USE_EXPERIMENT
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
|
||||
#else
|
||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||
#endif
|
||||
|
||||
iTotal++;
|
||||
inArea++;
|
||||
@ -339,8 +353,16 @@ void CheckArea(long Area)
|
||||
do_pack = TRUE;
|
||||
}
|
||||
iErrors++;
|
||||
#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
|
||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||
#endif
|
||||
} else {
|
||||
/*
|
||||
* File exists, now check the file.
|
||||
@ -488,21 +510,39 @@ void CheckArea(long Area)
|
||||
}
|
||||
Marker();
|
||||
if (Update) {
|
||||
#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
|
||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(fdb.Magic)) {
|
||||
rc = magic_check(fdb.Magic, fdb.Name);
|
||||
if (rc == -1) {
|
||||
Syslog('+', "Area %ld magic alias %s file %s is invalid", Area, fdb.Magic, fdb.Name);
|
||||
memset(&fdb.Magic, 0, sizeof(fdb.Magic));
|
||||
#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
|
||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||
#endif
|
||||
iErrors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inArea == 0)
|
||||
Syslog('+', "Warning: area %ld (%s) is empty", Area, area.Name);
|
||||
|
||||
@ -516,8 +556,13 @@ void CheckArea(long Area)
|
||||
if (de->d_name[0] != '.') {
|
||||
Marker();
|
||||
Found = FALSE;
|
||||
#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) {
|
||||
#endif
|
||||
if ((strcmp(fdb.LName, de->d_name) == 0) || (strcmp(fdb.Name, de->d_name) == 0)) {
|
||||
if (!Found) {
|
||||
Found = TRUE;
|
||||
@ -530,8 +575,16 @@ void CheckArea(long Area)
|
||||
iErrors++;
|
||||
fdb.Double = TRUE;
|
||||
do_pack = TRUE;
|
||||
#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
|
||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -560,11 +613,15 @@ void CheckArea(long Area)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_EXPERIMENT
|
||||
mbsedb_CloseFDB(fdb_area);
|
||||
#else
|
||||
fclose(pFile);
|
||||
chmod(fAreas, 0660);
|
||||
iAreasNew++;
|
||||
|
||||
free(fAreas);
|
||||
#endif
|
||||
|
||||
iAreasNew++;
|
||||
free(newdir);
|
||||
free(temp);
|
||||
free(mname);
|
||||
|
Reference in New Issue
Block a user