Updated for fdb code

This commit is contained in:
Michiel Broek 2004-05-06 19:25:53 +00:00
parent c32db895f6
commit 50fc461910
2 changed files with 102 additions and 14 deletions

View File

@ -124,7 +124,7 @@ depend:
# DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT
# Dependencies generated by make depend
addbbs.o: ../config.h ../lib/mbselib.h tic.h fsort.h addbbs.h
addbbs.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h tic.h fsort.h addbbs.h
backalias.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h backalias.h
flock.o: ../config.h ../lib/mbselib.h flock.h
hatch.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h utic.h rollover.h hatch.h

View File

@ -30,6 +30,8 @@
#include "../config.h"
#include "../lib/mbselib.h"
#include "../lib/users.h"
#include "../lib/mbsedb.h"
#include "tic.h"
#include "fsort.h"
#include "addbbs.h"
@ -50,11 +52,16 @@ int Add_BBS()
{
struct FILE_recordhdr frechdr;
struct FILE_record frec;
int rc, i, Insert, Done = FALSE, Found = FALSE, Keep = 0, DidDelete = FALSE;
char fdbname[PATH_MAX], fdbtemp[PATH_MAX];
int rc, i, Found = FALSE, Keep = 0, DidDelete = FALSE;
char temp1[PATH_MAX], temp2[PATH_MAX], *fname, *lname, *p;
FILE *fp, *fdt;
fd_list *fdl = NULL;
#ifdef USE_EXPERIMENT
struct _fdbarea *fdb_area = NULL;
#else
int Insert, Done = FALSE;
char fdbname[PATH_MAX], fdbtemp[PATH_MAX];
FILE *fp, *fdt;
#endif
/*
* First check for an existing record with the same filename,
@ -62,17 +69,26 @@ int Add_BBS()
* prevent for example allfiles.zip to get a new record everytime
* and thus the download counters will be reset after a new update.
*/
#ifdef USE_EXPERIMENT
if ((fdb_area = mbsedb_OpenFDB(tic.FileArea, 30))) {
while (fread(&frec, frechdr.recsize, 1, fdb_area->fp) == 1) {
#else
sprintf(fdbname, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), tic.FileArea);
if ((fp = fopen(fdbname, "r+")) != NULL) {
fread(&frechdr, sizeof(frechdr), 1, fp);
while (fread(&frec, frechdr.recsize, 1, fp) == 1) {
#endif
if (strcmp(frec.Name, TIC.NewFile) == 0) {
sprintf(temp1, "%s/%s", TIC.Inbound, TIC.NewFile);
sprintf(temp2, "%s/%s", TIC.BBSpath, TIC.NewFile);
mkdirs(temp2, 0755);
if ((rc = file_cp(temp1, temp2))) {
WriteError("Copy to %s failed: %s", temp2, strerror(rc));
#ifdef USE_EXPERIMENT
mbsedb_CloseFDB(fdb_area);
#else
fclose(fp);
#endif
return FALSE;
}
chmod(temp2, 0644);
@ -87,16 +103,29 @@ int Add_BBS()
if (i == 24)
break;
}
#ifdef USE_EXPERIMENT
if (mbsedb_LockFDB(fdb_area, 30)) {
fseek(fdb_area->fp, 0 - sizeof(frec), SEEK_CUR);
fwrite(&frec, sizeof(frec), 1, fdb_area->fp);
mbsedb_UnlockFDB(fdb_area);
}
mbsedb_CloseFDB(fdb_area);
#else
fseek(fp, 0 - sizeof(frec), SEEK_CUR);
fwrite(&frec, sizeof(frec), 1, fp);
fclose(fp);
#endif
tic_imp++;
if ((i = file_rm(temp1)))
WriteError("file_rm(%s): %s", temp1, strerror(i));
return TRUE;
}
}
#ifdef USE_EXPERIMENT
mbsedb_CloseFDB(fdb_area);
#else
fclose(fp);
#endif
}
@ -167,6 +196,12 @@ int Add_BBS()
}
free(lname);
#ifdef USE_EXPERIMENT
if ((fdb_area = mbsedb_OpenFDB(tic.FileArea, 30)) == NULL)
return FALSE;
mbsedb_InsertFDB(fdb_area, frec, area.AddAlpha);
mbsedb_CloseFDB(fdb_area);
#else
sprintf(fdbtemp, "%s/fdb/file%ld.temp", getenv("MBSE_ROOT"), tic.FileArea);
if ((fp = fopen(fdbname, "r+")) == NULL) {
Syslog('+', "Fdb %s doesn't exist, creating", fdbname);
@ -309,6 +344,7 @@ int Add_BBS()
fwrite(&frec, frechdr.recsize, 1, fp);
fclose(fp);
}
#endif
/*
* Delete file from the inbound
@ -322,11 +358,14 @@ int Add_BBS()
if ((strlen(TIC.TicIn.Replace)) && (tic.Replace)) {
Syslog('f', "Must Replace: %s", TIC.TicIn.Replace);
#ifdef USE_EXPERIMENT
if ((fdb_area = mbsedb_OpenFDB(tic.FileArea, 30))) {
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
#else
if ((fp = fopen(fdbname, "r+")) != NULL) {
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1) {
#endif
if (strlen(fdb.LName) == strlen(frec.LName)) {
// FIXME: Search must be based on a reg_exp search
if (strcasecmp(fdb.LName, frec.LName) != 0) {
@ -338,14 +377,26 @@ int Add_BBS()
if (Found) {
Syslog('+', "Replace: Deleting: %s", fdb.LName);
fdb.Deleted = 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(fp , - fdbhdr.recsize, SEEK_CUR);
fwrite(&fdb, fdbhdr.recsize, 1, fp);
#endif
DidDelete = TRUE;
}
}
}
}
#ifdef USE_EXPERIMENT
mbsedb_CloseFDB(fdb_area);
#else
fclose(fp);
#endif
}
}
@ -353,12 +404,14 @@ int Add_BBS()
* Handle the Keep number of files option
*/
if (TIC.KeepNum) {
#ifdef USE_EXPERIMENT
if ((fdb_area = mbsedb_OpenFDB(tic.FileArea, 30))) {
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
#else
if ((fp = fopen(fdbname, "r")) != NULL) {
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1) {
#endif
if ((strlen(fdb.LName) == strlen(frec.LName)) && (!fdb.Deleted)) {
Found = TRUE;
@ -375,7 +428,11 @@ int Add_BBS()
}
}
}
#ifdef USE_EXPERIMENT
mbsedb_CloseFDB(fdb_area);
#else
fclose(fp);
#endif
}
/*
@ -384,24 +441,43 @@ int Add_BBS()
if (Keep > TIC.KeepNum) {
sort_fdlist(&fdl);
#ifdef USE_EXPERIMENT
if ((fdb_area = mbsedb_OpenFDB(tic.FileArea, 30))) {
#else
if ((fp = fopen(fdbname, "r+")) != NULL) {
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
#endif
for (i = 0; i < (Keep - TIC.KeepNum); i++) {
fname = pull_fdlist(&fdl);
#ifdef USE_EXPERIMENT
fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET);
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
#else
fseek(fp, fdbhdr.hdrsize, SEEK_SET);
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1) {
#endif
if (strcmp(fdb.LName, fname) == 0) {
Syslog('+', "Keep %d files, deleting: %s", TIC.KeepNum, fdb.LName);
fdb.Deleted = 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(fp , - fdbhdr.recsize, SEEK_CUR);
fwrite(&fdb, fdbhdr.recsize, 1, fp);
#endif
DidDelete = TRUE;
}
}
}
#ifdef USE_EXPERIMENT
mbsedb_CloseFDB(fdb_area);
#else
fclose(fp);
#endif
}
}
tidy_fdlist(&fdl);
@ -412,14 +488,21 @@ int Add_BBS()
* database.
*/
if (DidDelete) {
#ifdef USE_EXPERIMENT
if ((fdb_area = mbsedb_OpenFDB(tic.FileArea, 30))) {
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1)
#else
if ((fp = fopen(fdbname, "r")) != NULL) {
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
if ((fdt = fopen(fdbtemp, "a+")) != NULL) {
fwrite(&fdbhdr, fdbhdr.hdrsize, 1, fdt);
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1)
if (!fdb.Deleted)
#endif
if (!fdb.Deleted) {
#ifndef USE_EXPERIMENT
fwrite(&fdb, fdbhdr.recsize, 1, fdt);
else {
#endif
} else {
sprintf(temp2, "%s/%s", area.Path, fdb.LName);
if (unlink(temp2) != 0)
WriteError("$Can't unlink file %s", temp2);
@ -429,6 +512,10 @@ int Add_BBS()
sprintf(temp2, "%s/.%s", area.Path, fdb.Name);
unlink(temp2); /* Thumbnail, no logging if there is an error */
}
#ifdef USE_EXPERIMENT
mbsedb_PackFDB(fdb_area);
mbsedb_CloseFDB(fdb_area);
#else
fclose(fp);
fclose(fdt);
if (unlink(fdbname) == 0) {
@ -440,6 +527,7 @@ int Add_BBS()
} else {
fclose(fp);
}
#endif
DidDelete = FALSE;
}
}