Made magic cleanup in fdb permanent

This commit is contained in:
Michiel Broek 2004-09-25 11:02:29 +00:00
parent b605aba2d0
commit 75051be04a
2 changed files with 63 additions and 76 deletions

View File

@ -34,8 +34,8 @@ v0.61.4 11-Aug-2004
cleaned magic aliases. cleaned magic aliases.
Fixed a problem with the files database were the temp file used Fixed a problem with the files database were the temp file used
for sorting and inserting files didn't close the temp file. for sorting and inserting files didn't close the temp file.
Changed method of inserting new files that now hopefully old Changed method of inserting new files so that old magic names
magic names are really cleared. are really cleared.
mbcico: mbcico:
Removed a little debug logging. Removed a little debug logging.

View File

@ -258,89 +258,76 @@ int mbsedb_InsertFDB(struct _fdbarea *fdb_area, struct FILE_record frec, int Add
} }
} while ((!Found) && (!Done)); } while ((!Found) && (!Done));
Syslog('f', "mbsedb_InsertFDB: insertpoint=%d, found=%s, done=%s", Insert, Found?"true":"false", Done?"true":"false"); if ((fp = fopen(temp, "a+")) == NULL) {
WriteError("$Can't create %s", temp);
mbsedb_UnlockFDB(fdb_area);
free(temp);
return FALSE;
}
fwrite(&fdbhdr, sizeof(fdbhdr), 1, fp);
// if (Found) { fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET);
if ((fp = fopen(temp, "a+")) == NULL) { /*
WriteError("$Can't create %s", temp); * Copy entries untill the insert point.
mbsedb_UnlockFDB(fdb_area); */
free(temp); for (i = 0; i < Insert; i++) {
return FALSE; fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
} /*
fwrite(&fdbhdr, sizeof(fdbhdr), 1, fp); * If we see a magic that is the new magic, remove the old one.
*/
fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET); if (strlen(frec.Magic) && (strcmp(fdb.Magic, frec.Magic) == 0)) {
/* Syslog('f', "Clear magic %s file %s", fdb.Magic, fdb.LName);
* Copy entries untill the insert point. memset(&fdb.Magic, 0, sizeof(fdb.Magic));
*/
for (i = 0; i < Insert; i++) {
fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
/*
* If we see a magic that is the new magic, remove
* the old one.
*/
if (strlen(frec.Magic) && (strcmp(fdb.Magic, frec.Magic) == 0)) {
Syslog('f', "Clear magic %s file %s", fdb.Magic, fdb.LName);
memset(&fdb.Magic, 0, sizeof(fdb.Magic));
}
/*
* Check if we are importing a file with the same
* name, if so, don't copy the original database
* record. The file is also overwritten.
*/
if (strcmp(fdb.LName, frec.LName) != 0)
fwrite(&fdb, fdbhdr.recsize, 1, fp);
}
if (AddAlpha) {
/*
* Insert new entry
*/
fwrite(&frec, fdbhdr.recsize, 1, fp);
} }
/* /*
* Append the rest of the entries * Check if we are importing a file with the same
*/ * name, if so, don't copy the original database
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) { * record. The file is also overwritten.
/* */
* If we see a magic that is the new magic, remove if (strcmp(fdb.LName, frec.LName) != 0)
* the old one. fwrite(&fdb, fdbhdr.recsize, 1, fp);
*/ }
if (strlen(frec.Magic) && (strcmp(fdb.Magic, frec.Magic) == 0)) {
Syslog('f', "Clear magic %s file %s", fdb.Magic, fdb.LName);
memset(&fdb.Magic, 0, sizeof(fdb.Magic));
}
/* if (AddAlpha) {
* Check if we are importing a file with the same /*
* name, if so, don't copy the original database * Insert new entry
* record. The file is also overwritten. */
*/ fwrite(&frec, fdbhdr.recsize, 1, fp);
if (strcmp(fdb.LName, frec.LName) != 0) }
fwrite(&fdb, fdbhdr.recsize, 1, fp);
/*
* Append the rest of the entries
*/
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
/*
* If we see a magic that is the new magic, remove the old one.
*/
if (strlen(frec.Magic) && (strcmp(fdb.Magic, frec.Magic) == 0)) {
Syslog('f', "Clear magic %s file %s", fdb.Magic, fdb.LName);
memset(&fdb.Magic, 0, sizeof(fdb.Magic));
} }
if (! AddAlpha) { /*
/* * Check if we are importing a file with the same
* Append * name, if so, don't copy the original database
*/ * record. The file is also overwritten.
fwrite(&frec, fdbhdr.recsize, 1, fp); */
} if (strcmp(fdb.LName, frec.LName) != 0)
fwrite(&fdb, fdbhdr.recsize, 1, fp);
}
fclose(fdb_area->fp); if (! AddAlpha) {
mbsedb_Temp2Data(fdb_area->area); /*
fdb_area->fp = fp; * Append
fdb_area->locked = 0; */
// } else { fwrite(&frec, fdbhdr.recsize, 1, fp);
/* }
* Append new entry
*/
// fseek(fdb_area->fp, 0, SEEK_END);
// fwrite(&frec, fdbhdr.recsize, 1, fdb_area->fp);
// }
fclose(fdb_area->fp);
mbsedb_Temp2Data(fdb_area->area);
fdb_area->fp = fp;
fdb_area->locked = 0;
free(temp); free(temp);
return TRUE; return TRUE;