From 75051be04aae282a85df417841fded95391862ba Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 25 Sep 2004 11:02:29 +0000 Subject: [PATCH] Made magic cleanup in fdb permanent --- ChangeLog | 4 +- lib/dbfdb.c | 135 ++++++++++++++++++++++++---------------------------- 2 files changed, 63 insertions(+), 76 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0358da03..47fe5e95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -34,8 +34,8 @@ v0.61.4 11-Aug-2004 cleaned magic aliases. Fixed a problem with the files database were the temp file used for sorting and inserting files didn't close the temp file. - Changed method of inserting new files that now hopefully old - magic names are really cleared. + Changed method of inserting new files so that old magic names + are really cleared. mbcico: Removed a little debug logging. diff --git a/lib/dbfdb.c b/lib/dbfdb.c index f12d3bea..9938df5a 100644 --- a/lib/dbfdb.c +++ b/lib/dbfdb.c @@ -258,89 +258,76 @@ int mbsedb_InsertFDB(struct _fdbarea *fdb_area, struct FILE_record frec, int Add } } 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) { - 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); - - fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET); - /* - * Copy entries untill the insert point. - */ - 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); + fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET); + /* + * Copy entries untill the insert point. + */ + 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)); } /* - * 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)); - } + * 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); + } - /* - * 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 + */ + 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) { - /* - * Append - */ - fwrite(&frec, fdbhdr.recsize, 1, fp); - } + /* + * 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); + } - fclose(fdb_area->fp); - mbsedb_Temp2Data(fdb_area->area); - fdb_area->fp = fp; - fdb_area->locked = 0; -// } else { - /* - * Append new entry - */ -// fseek(fdb_area->fp, 0, SEEK_END); -// fwrite(&frec, fdbhdr.recsize, 1, fdb_area->fp); -// } + if (! AddAlpha) { + /* + * Append + */ + fwrite(&frec, fdbhdr.recsize, 1, fp); + } + fclose(fdb_area->fp); + mbsedb_Temp2Data(fdb_area->area); + fdb_area->fp = fp; + fdb_area->locked = 0; free(temp); return TRUE;