Fix GoldED style LastRead records

This commit is contained in:
Michiel Broek 2007-09-02 15:30:02 +00:00
parent 9b545491ca
commit b7aaed6491
2 changed files with 46 additions and 14 deletions

View File

@ -25,6 +25,9 @@ v0.91.10 21-Aug-2007
disk i/o. disk i/o.
LastRead records that don't belong to a valid user are LastRead records that don't belong to a valid user are
purged. purged.
LastRead pointers are searched via an alternate method if the
record is created by GoldED.
Don't purge GoldED style LastRead records but fix them.
mbcico: mbcico:
Fixed a lot of compiler warnings. Fixed a lot of compiler warnings.

View File

@ -386,7 +386,20 @@ int JAM_GetLastRead(lastread *LR)
lseek(fdJlr, 0, SEEK_SET); lseek(fdJlr, 0, SEEK_SET);
while (read(fdJlr, &lr, sizeof(lastread)) == sizeof(lastread)) { while (read(fdJlr, &lr, sizeof(lastread)) == sizeof(lastread)) {
if (lr.UserID == LR->UserID) { /*
* Check for GoldED bug, the CRC == ID so the ID is invalid.
* Test for a valid CRC to find the right record.
*/
if ((lr.UserID == lr.UserCRC) && (lr.UserCRC == LR->UserCRC)) {
Syslog('m', "Found LR record for user %d using a workaround", LR->UserID);
LR->LastReadMsg = lr.LastReadMsg;
LR->HighReadMsg = lr.HighReadMsg;
return TRUE;
}
/*
* The way it should be.
*/
if ((lr.UserID != lr.UserCRC) && (lr.UserID == LR->UserID)) {
LR->LastReadMsg = lr.LastReadMsg; LR->LastReadMsg = lr.LastReadMsg;
LR->HighReadMsg = lr.HighReadMsg; LR->HighReadMsg = lr.HighReadMsg;
return TRUE; return TRUE;
@ -636,7 +649,7 @@ void JAM_Pack(void)
int ToRead, Readed, i, count; int ToRead, Readed, i, count;
char *File, *New, *Subfield, *Temp; char *File, *New, *Subfield, *Temp;
JAMIDXREC jamIdx; JAMIDXREC jamIdx;
unsigned int NewNumber = 0, RefNumber = 0, Written = 0, mycrc; unsigned int NewNumber = 0, RefNumber = 0, Written = 0, mycrc, myrec;
lastread LR; lastread LR;
FILE *usrF; FILE *usrF;
struct userhdr usrhdr; struct userhdr usrhdr;
@ -784,6 +797,21 @@ void JAM_Pack(void)
Syslog('m', "JAM_Pack %s recno %d user %d HighRead is reset to %d", BaseName, i, LR.UserID, LR.HighReadMsg); Syslog('m', "JAM_Pack %s recno %d user %d HighRead is reset to %d", BaseName, i, LR.UserID, LR.HighReadMsg);
} }
if (usrF) { if (usrF) {
if ((LR.UserID == LR.UserCRC) && LR.UserCRC) {
/*
* GoldED bug, try to fix it. This might leave double records, we
* will deal with that later. TODO: write that code!
*/
fseek(usrF, usrhdr.hdrsize, SEEK_SET);
myrec = 0;
while (fread(&usr, usrhdr.recsize, 1, usrF) == 1) {
mycrc = StringCRC32(tl(usr.sUserName));
if (LR.UserCRC == mycrc) {
LR.UserID = myrec;
Syslog('m', "JAM_Pack %s recno %d LastRead UserID set to %d", BaseName, i, myrec);
}
}
} else {
/* /*
* Search user record for LR pointer. If the record is valid and the * Search user record for LR pointer. If the record is valid and the
* user still exists then copy the LR record, else we drop it. * user still exists then copy the LR record, else we drop it.
@ -800,6 +828,7 @@ void JAM_Pack(void)
} else { } else {
Syslog('-', "JAM_Pack %s purged LR record %d", BaseName, i); Syslog('-', "JAM_Pack %s purged LR record %d", BaseName, i);
} }
}
} else { } else {
/* /*
* Should not be possible, but simply write LR records * Should not be possible, but simply write LR records