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