2001-11-18 23:19:08 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
* Purpose: File Database Maintenance - Pack filebase
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2005-08-19 20:48:54 +00:00
|
|
|
* Copyright (C) 1997-2005
|
2001-11-18 23:19:08 +00:00
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* MBSE BBS is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
2003-08-15 20:05:34 +00:00
|
|
|
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
2001-11-18 23:19:08 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-06-30 12:48:44 +00:00
|
|
|
#include "../config.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbselib.h"
|
2002-01-07 19:16:03 +00:00
|
|
|
#include "../lib/users.h"
|
2004-02-21 17:22:00 +00:00
|
|
|
#include "../lib/mbsedb.h"
|
2001-11-18 23:19:08 +00:00
|
|
|
#include "mbfutil.h"
|
|
|
|
#include "mbfpack.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-06-19 20:31:35 +00:00
|
|
|
extern int do_quiet; /* Suppress screen output */
|
2001-12-07 22:19:55 +00:00
|
|
|
extern int do_index; /* Reindex filebases */
|
2001-11-18 23:19:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Removes records who are marked for deletion. If there is still a file
|
|
|
|
* on disk, it will be removed too.
|
|
|
|
*/
|
|
|
|
void PackFileBase(void)
|
|
|
|
{
|
2004-05-06 14:32:05 +00:00
|
|
|
FILE *pAreas;
|
2002-11-23 16:48:54 +00:00
|
|
|
int i, iAreas, iAreasNew = 0, rc, iTotal = 0, iRemoved = 0;
|
2004-05-06 14:32:05 +00:00
|
|
|
char *sAreas, fn[PATH_MAX];
|
|
|
|
struct _fdbarea *fdb_area = NULL;
|
2004-05-06 14:51:45 +00:00
|
|
|
int purge;
|
2004-05-06 14:32:05 +00:00
|
|
|
|
|
|
|
sAreas = calloc(PATH_MAX, sizeof(char));
|
2002-11-23 16:48:54 +00:00
|
|
|
|
|
|
|
IsDoing("Pack filebase");
|
|
|
|
if (!do_quiet) {
|
2005-08-19 20:48:54 +00:00
|
|
|
mbse_colour(CYAN, BLACK);
|
2002-11-23 16:48:54 +00:00
|
|
|
printf("Packing file database...\n");
|
|
|
|
}
|
|
|
|
|
2005-08-28 14:10:06 +00:00
|
|
|
snprintf(sAreas, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
|
2002-11-23 16:48:54 +00:00
|
|
|
|
|
|
|
if ((pAreas = fopen (sAreas, "r")) == NULL) {
|
|
|
|
WriteError("Can't open %s", sAreas);
|
|
|
|
die(MBERR_INIT_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
fread(&areahdr, sizeof(areahdr), 1, pAreas);
|
|
|
|
fseek(pAreas, 0, SEEK_END);
|
|
|
|
iAreas = (ftell(pAreas) - areahdr.hdrsize) / areahdr.recsize;
|
2001-11-18 23:19:08 +00:00
|
|
|
|
2002-11-23 16:48:54 +00:00
|
|
|
for (i = 1; i <= iAreas; i++) {
|
|
|
|
|
|
|
|
fseek(pAreas, ((i-1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET);
|
|
|
|
fread(&area, areahdr.recsize, 1, pAreas);
|
|
|
|
|
2005-08-11 21:05:15 +00:00
|
|
|
if (area.Available) {
|
2002-11-23 16:48:54 +00:00
|
|
|
|
2004-03-21 12:55:45 +00:00
|
|
|
if (enoughspace(CFG.freespace) == 0)
|
2002-11-23 16:48:54 +00:00
|
|
|
die(MBERR_DISK_FULL);
|
|
|
|
|
|
|
|
if (!do_quiet) {
|
|
|
|
printf("\r%4d => %-44s", i, area.Name);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
Marker();
|
|
|
|
|
2004-05-06 14:32:05 +00:00
|
|
|
if ((fdb_area = mbsedb_OpenFDB(i, 30)) == NULL)
|
|
|
|
die(MBERR_GENERAL);
|
2004-05-06 14:51:45 +00:00
|
|
|
purge = 0;
|
2002-11-23 16:48:54 +00:00
|
|
|
|
2004-05-06 14:32:05 +00:00
|
|
|
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
|
2002-11-23 16:48:54 +00:00
|
|
|
iTotal++;
|
|
|
|
|
2004-05-19 21:18:14 +00:00
|
|
|
if ((fdb.Deleted) || (fdb.Double) || (strcmp(fdb.Name, "") == 0)) {
|
2002-11-23 16:48:54 +00:00
|
|
|
iRemoved++;
|
2004-05-06 14:51:45 +00:00
|
|
|
purge++;
|
2004-03-06 21:48:41 +00:00
|
|
|
if (fdb.Double) {
|
|
|
|
Syslog('+', "Removed double record file \"%s\" from area %d", fdb.LName, i);
|
2002-11-23 16:48:54 +00:00
|
|
|
} else {
|
2004-03-06 21:48:41 +00:00
|
|
|
Syslog('+', "Removed file \"%s\" from area %d", fdb.LName, i);
|
2005-08-28 14:10:06 +00:00
|
|
|
snprintf(fn, PATH_MAX, "%s/%s", area.Path, fdb.LName);
|
2002-11-23 16:48:54 +00:00
|
|
|
rc = unlink(fn);
|
2002-12-09 19:08:18 +00:00
|
|
|
if (rc && (errno != ENOENT))
|
2005-12-16 20:12:17 +00:00
|
|
|
WriteError("PackFileBase(): unlink %s failed, result %s", fn, strerror(rc));
|
2005-08-28 14:10:06 +00:00
|
|
|
snprintf(fn, PATH_MAX, "%s/%s", area.Path, fdb.Name);
|
2002-11-23 16:48:54 +00:00
|
|
|
rc = unlink(fn);
|
2002-12-09 19:08:18 +00:00
|
|
|
if (rc && (errno != ENOENT))
|
2005-12-16 20:12:17 +00:00
|
|
|
WriteError("PackFileBase(): unlink %s failed, result %s", fn, strerror(rc));
|
2002-11-23 16:48:54 +00:00
|
|
|
/*
|
|
|
|
* If a dotted version (thumbnail) exists, remove it silently
|
|
|
|
*/
|
2005-08-28 14:10:06 +00:00
|
|
|
snprintf(fn, PATH_MAX, "%s/.%s", area.Path, fdb.Name);
|
2002-11-23 16:48:54 +00:00
|
|
|
unlink(fn);
|
|
|
|
}
|
|
|
|
do_index = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-06 14:51:45 +00:00
|
|
|
if (purge)
|
|
|
|
mbsedb_PackFDB(fdb_area);
|
2004-05-06 14:32:05 +00:00
|
|
|
mbsedb_CloseFDB(fdb_area);
|
2002-11-23 16:48:54 +00:00
|
|
|
iAreasNew++;
|
|
|
|
|
|
|
|
} /* if area.Available */
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(pAreas);
|
2005-08-26 15:53:46 +00:00
|
|
|
Syslog('+', "Pack Areas [%6d] Files [%6d] Removed [%6d]", iAreasNew, iTotal, iRemoved);
|
2002-11-23 16:48:54 +00:00
|
|
|
|
|
|
|
if (!do_quiet) {
|
|
|
|
printf("\r \r");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2004-05-06 14:32:05 +00:00
|
|
|
free(sAreas);
|
2001-11-18 23:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|