Added mbfile rearc

This commit is contained in:
Michiel Broek
2004-03-08 20:51:04 +00:00
parent ea5a8aa2a9
commit 79c89010d0
18 changed files with 594 additions and 112 deletions

View File

@@ -21,7 +21,7 @@ HDRS = addbbs.h backalias.h flock.h hatch.h mbdiff.h mgrutil.h qualify.h \
aliasdb.h fsort.h magic.h mbfile.h mover.h ping.h rfc2ftn.h \
storeecho.h unpack.h announce.h fflist.h ftn2rfc.h makestat.h mbindex.h \
msgutil.h post.h rnews.h storenet.h utic.h areamgr.h filefind.h \
grlist.h maketags.h mbmsg.h newspost.h postecho.h rollover.h tic.h \
grlist.h maketags.h mbmsg.h newspost.h postecho.h rollover.h tic.h mbfrearc.h \
atoul.h filemgr.h hash.h mbaff.h mbseq.h notify.h postemail.h scan.h toberep.h \
mbfkill.h mbfutil.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfadopt.h \
mbfimport.h mbfsort.h virscan.h mbftoberep.h mbfmove.h mbfdel.h bounce.h \
@@ -39,7 +39,7 @@ MBAFF_OBJS = announce.o fflist.o filefind.o grlist.o mbaff.o msgutil.o toberep.o
MBINDEX_OBJS = mbindex.o
MBDIFF_OBJS = mbdiff.o
MBFILE_OBJS = mbfile.o mbfkill.o mbfutil.o mbfindex.o mbfcheck.o mbfpack.o mbflist.o mbfadopt.o \
mbfimport.o virscan.o mbftoberep.o mbfmove.o mbfdel.o mbfsort.o
mbfimport.o virscan.o mbftoberep.o mbfmove.o mbfdel.o mbfsort.o mbfrearc.o
MBMSG_OBJS = post.o mbmsg.o
MBFIDO_LIBS = ../lib/libmbse.a ../lib/libmsgbase.a ../lib/libdbase.a ../lib/libdiesel.a ../lib/libmbinet.a ../lib/libnodelist.a
MBSEQ_LIBS = ../lib/libmbse.a ../lib/libdbase.a
@@ -147,7 +147,7 @@ unpack.o: ../config.h ../lib/mbselib.h flock.h unpack.h
aliasdb.o: ../config.h ../lib/mbselib.h aliasdb.h
fsort.o: ../config.h ../lib/mbselib.h fsort.h
magic.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h tic.h utic.h magic.h
mbfile.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbfkill.h mbfadopt.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfimport.h mbftoberep.h mbfmove.h mbfdel.h mbfutil.h mbfsort.h mbfile.h
mbfile.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h mbfkill.h mbfadopt.h mbfindex.h mbfcheck.h mbfpack.h mbflist.h mbfimport.h mbftoberep.h mbfmove.h mbfdel.h mbfutil.h mbfsort.h mbfile.h mbfrearc.h
mover.o: ../config.h ../lib/mbselib.h tic.h mover.h
post.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbsedb.h ../lib/msg.h ../lib/msgtext.h post.h
rnews.o: ../config.h ../lib/mbselib.h ../lib/users.h ../lib/mbinet.h ../lib/mbsedb.h ../lib/msg.h ../lib/msgtext.h rfc2ftn.h mbfido.h ../paths.h rnews.h

View File

@@ -104,7 +104,7 @@ int CheckHatch(char *temp)
struct dirent *de;
char *fn, *tf, tmp[4], *temp2;
int i, hatched = FALSE;
char *p, *q, mask[256];
char mask[256];
FILE *Tf;
fn = xstrcpy(strrchr(temp, '/') + 1);
@@ -125,26 +125,7 @@ int CheckHatch(char *temp)
return FALSE;
}
memset(&mask, 0, sizeof(mask));
p = fn;
q = mask;
*q++ = '^';
while ((*p) && (q < (mask + sizeof(mask) - 4))) {
switch(*p) {
case '\\': *q++ = '\\'; *q++ = '\\'; break;
case '?': *q++ = '.'; break;
case '.': *q++ = '\\'; *q++ = '.'; break;
case '+': *q++ = '\\'; *q++ = '+'; break;
case '*': *q++ = '.'; *q++ = '*'; break;
case '@': sprintf(q, "[A-Za-z]"); while (*q) q++; break;
case '#': sprintf(q, "[0-9]"); while (*q) q++; break;
default: *q++ = *p; break;
}
p++;
}
*q++ = '$';
*q = '\0';
strcpy(mask, re_mask(fn, FALSE));
if ((re_comp(mask)) == NULL) {
tf = calloc(PATH_MAX, sizeof(char));
while ((de = readdir(dp))) {

View File

@@ -83,7 +83,7 @@ char *Magic_Macro(int C)
int GetMagicRec(int Typ, int First)
{
int Eof = FALSE;
char *temp, *p, *q, mask[256];
char *temp, mask[256];
FILE *FeM;
if (First)
@@ -114,25 +114,7 @@ int GetMagicRec(int Typ, int First)
if ((magic.Active) && (magic.Attrib == Typ) && (strcasecmp(magic.From, TIC.TicIn.Area) == 0)) {
memset(&mask, 0, sizeof(mask));
p = magic.Mask;
q = mask;
*q++ = '^';
while ((*p) && (q < (mask + sizeof(mask) - 4))) {
switch(*p) {
case '\\': *q++ = '\\'; *q++ = '\\'; break;
case '?': *q++ = '.'; break;
case '.': *q++ = '\\'; *q++ = '.'; break;
case '+': *q++ = '\\'; *q++ = '+'; break;
case '*': *q++ = '.'; *q++ = '*'; break;
case '@': sprintf(q, "[A-Za-z]"); while (*q) q++; break;
case '#': sprintf(q, "[0-9]"); while (*q) q++; break;
default: *q++ = *p; break;
}
p++;
}
*q++ = '$';
*q = '\0';
strcpy(mask, re_mask(magic.Mask, FALSE));
if ((re_comp(mask)) == NULL) {
if (re_exec(TIC.NewFile)) {
fclose(FeM);

View File

@@ -227,6 +227,9 @@ void Check(void)
tname = calloc(PATH_MAX, sizeof(char));
sprintf(tname, "%s/%s", area.Path, fdb.Name);
rename(tname, mname);
sprintf(tname, "%s/%s", area.Path, fdb.LName);
unlink(tname);
symlink(mname, tname);
free(tname);
strncpy(fdb.Name, temp, 12);
iErrors++;

View File

@@ -46,7 +46,7 @@ extern int do_quiet; /* Suppress screen output */
*/
void Delete(int UnDel, int Area, char *File)
{
char *temp;
char *temp, mask[256];
FILE *fp;
int rc = FALSE;
@@ -84,29 +84,32 @@ void Delete(int UnDel, int Area, char *File)
if ((fp = fopen(temp, "r+")) == NULL)
die(MBERR_GENERAL);
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
colour(CYAN, BLACK);
strcpy(mask, re_mask(File, FALSE));
if (re_comp(mask))
die(MBERR_GENERAL);
while (fread(&fdb, sizeof(fdb), 1, fp) == 1) {
if ((! strcmp(fdb.LName, File) || (! strcmp(fdb.Name, File)))) {
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1) {
if (re_exec(fdb.LName) || re_exec(fdb.Name)) {
if (UnDel && fdb.Deleted) {
fdb.Deleted = FALSE;
Syslog('+', "Marked file %s in area %d for undeletion", File, Area);
Syslog('+', "Marked file %s in area %d for undeletion", fdb.Name, Area);
if (!do_quiet)
printf("Marked file %s in area %d for undeletion\n", File, Area);
printf("Marked file %s in area %d for undeletion\n", fdb.Name, Area);
rc = TRUE;
}
if (!UnDel && !fdb.Deleted) {
fdb.Deleted = TRUE;
Syslog('+', "Marked file %s in area %d for deletion", File, Area);
Syslog('+', "Marked file %s in area %d for deletion", fdb.Name, Area);
if (!do_quiet)
printf("Marked file %s in area %d for deletion\n", File, Area);
printf("Marked file %s in area %d for deletion\n", fdb.Name, Area);
rc = TRUE;
}
if (rc) {
fseek(fp, - sizeof(fdb), SEEK_CUR);
fwrite(&fdb, sizeof(fdb), 1, fp);
fseek(fp, - fdbhdr.recsize, SEEK_CUR);
fwrite(&fdb, fdbhdr.recsize, 1, fp);
}
break;
}
}
fclose(fp);

View File

@@ -45,7 +45,7 @@
#include "mbfutil.h"
#include "mbfsort.h"
#include "mbfile.h"
#include "mbfrearc.h"
extern int do_quiet; /* Suppress screen output */
@@ -62,6 +62,7 @@ int do_tobe = FALSE; /* List toberep database */
int do_move = FALSE; /* Move a file */
int do_del = FALSE; /* Delete/undelete a file */
int do_sort = FALSE; /* Sort a filebase */
int do_rearc = FALSE; /* ReArc a file */
extern int e_pid; /* Pid of external process */
extern int show_log; /* Show logging */
time_t t_start; /* Start time */
@@ -137,6 +138,20 @@ int main(int argc, char **argv)
do_del = TRUE;
}
}
} else if (!strncasecmp(argv[i], "r", 1)) {
if (argc > (i + 1)) {
i++;
Area = atoi(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
if (argc > (i + 1)) {
i++;
FileName = xstrcpy(argv[i]);
cmd = xstrcat(cmd, (char *)" ");
cmd = xstrcat(cmd, argv[i]);
do_rearc = TRUE;
}
}
} else if (!strncasecmp(argv[i], "in", 2)) {
do_index = TRUE;
} else if (!strncasecmp(argv[i], "im", 2)) {
@@ -201,7 +216,7 @@ int main(int argc, char **argv)
}
if (!(do_pack || do_sort || do_check || do_kill || do_index || do_import ||
do_list || do_adopt || do_del || do_move || do_tobe))
do_list || do_adopt || do_del || do_move || do_tobe || do_rearc))
Help();
ProgName();
@@ -263,6 +278,11 @@ int main(int argc, char **argv)
die(MBERR_OK);
}
if (do_rearc) {
ReArc(Area, FileName);
die(MBERR_OK);
}
if (do_list) {
ListFileAreas(Area);
die(MBERR_OK);

View File

@@ -43,8 +43,7 @@ extern int do_quiet; /* Suppress screen output */
void ListFileAreas(int Area)
{
FILE *pAreas, *pFile, *pTic;
int i, iAreas, fcount, tcount = 0;
int iTotal = 0;
int i, iAreas, fcount, tcount = 0, iTotal = 0, columns = 80;
long fsize, tsize = 0;
char *sAreas, *fAreas, *sTic, flags[6], *ticarea;
@@ -54,6 +53,15 @@ void ListFileAreas(int Area)
if (do_quiet)
return;
/*
* See if we know the width of the users screen.
*/
if (getenv("COLUMNS")) {
i = atoi(getenv("COLUMNS"));
if (i >= 80)
columns = i;
}
colour(LIGHTRED, BLACK);
sAreas = calloc(PATH_MAX, sizeof(char));
fAreas = calloc(PATH_MAX, sizeof(char));
@@ -118,7 +126,7 @@ void ListFileAreas(int Area)
printf("File listing of area %d, %s\n\n", Area, area.Name);
printf("Short name Kb. File date Down Flg TIC Area Long name\n");
printf("------------ ----- ---------- ---- --- -------------------- ");
for (i = 63; i < COLS; i++)
for (i = 60; i < columns; i++)
printf("-");
printf("\n");
@@ -133,7 +141,7 @@ void ListFileAreas(int Area)
if (fdb.Announced)
flags[2] = 'A';
fdb.LName[COLS - 63] = '\0';
fdb.LName[columns - 60] = '\0';
printf("%-12s %5ld %s %4ld %s %-20s %s\n", fdb.Name, (long)(fdb.Size / 1024), StrDateDMY(fdb.FileDate),
(long)(fdb.TimesDL), flags, fdb.TicArea, fdb.LName);
fcount++;
@@ -142,8 +150,8 @@ void ListFileAreas(int Area)
fsize = fsize / 1024;
colour(CYAN, BLACK);
printf("--------------------------------------------------------------");
for (i = 63; i < COLS; i++)
printf("------------------------------------------------------------");
for (i = 60; i < columns; i++)
printf("-");
printf("\n");
printf("%d file%s, %ld Kbytes\n", fcount, (fcount == 1) ? "":"s", fsize);

196
mbfido/mbfrearc.c Normal file
View File

@@ -0,0 +1,196 @@
/*****************************************************************************
*
* $Id$
* Purpose: File Database Maintenance - ReArc file(s)
*
*****************************************************************************
* Copyright (C) 1997-2004
*
* 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
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*****************************************************************************/
#include "../config.h"
#include "../lib/mbselib.h"
#include "../lib/users.h"
#include "../lib/mbsedb.h"
#include "mbfutil.h"
#include "mbfmove.h"
extern int do_quiet; /* Suppress screen output */
/*
* ReArc file(s)
*/
void ReArc(int Area, char *File)
{
char *p, *temp, *linkpath, mask[256];
FILE *fp;
int i, rc = -1;
struct utimbuf ut;
IsDoing("ReArc file(s)");
colour(LIGHTRED, BLACK);
/*
* Check area
*/
if (LoadAreaRec(Area) == FALSE) {
WriteError("Can't load record %d", Area);
die(MBERR_INIT_ERROR);
}
if (!area.Available) {
WriteError("Area %d not available", Area);
if (!do_quiet)
printf("Area %d not available\n", Area);
die(MBERR_CONFIG_ERROR);
}
if (area.CDrom) {
WriteError("Can't rearc on CD-ROM");
if (!do_quiet)
printf("Can't rearc on CD-ROM\n");
die(MBERR_COMMANDLINE);
}
if (strlen(area.Archiver) == 0) {
WriteError("No default archiver for area %d", Area);
if (!do_quiet)
printf("No default archiver for area %d\n", Area);
die(MBERR_COMMANDLINE);
}
if (CheckFDB(Area, area.Path))
die(MBERR_GENERAL);
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/fdb/file%d.data", getenv("MBSE_ROOT"), Area);
if ((fp = fopen(temp, "r+")) == NULL)
die(MBERR_GENERAL);
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
colour(CYAN, BLACK);
strcpy(mask, re_mask(File, FALSE));
if (re_comp(mask))
die(MBERR_GENERAL);
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1) {
if (re_exec(fdb.LName) || re_exec(fdb.Name)) {
Syslog('+', "Will rearc %s", fdb.LName);
sprintf(temp, "%s/%s", area.Path, fdb.Name);
rc = rearc(temp, area.Archiver, do_quiet);
if (rc == 0) {
/*
* Success, update the file entry
*/
if (!do_quiet) {
colour(9, 0);
printf("\r Update file %s", temp);
fflush(stdout);
}
linkpath = calloc(PATH_MAX, sizeof(char));
sprintf(linkpath, "%s/%s", area.Path, fdb.LName);
unlink(linkpath);
Syslog('+', "New name %s", temp);
if ((p = strstr(fdb.Name, "ARC")))
*p = '\0';
else if ((p = strstr(fdb.Name, "LHA")))
*p = '\0';
else if ((p = strstr(fdb.Name, "RAR")))
*p = '\0';
else if ((p = strstr(fdb.Name, "TGZ")))
*p = '\0';
else if ((p = strstr(fdb.Name, "BZ2")))
*p = '\0';
else if ((p = strstr(fdb.Name, "TAR")))
*p = '\0';
else if ((p = strstr(fdb.Name, "ARJ")))
*p = '\0';
else if ((p = strstr(fdb.Name, "ZIP")))
*p = '\0';
else if ((p = strstr(fdb.Name, "ZOO")))
*p = '\0';
else if ((p = strstr(fdb.Name, "HA")))
*p = '\0';
sprintf(p, "%s", archiver.name);
if ((p = strstr(fdb.LName, "arc")))
*p = '\0';
else if ((p = strstr(fdb.LName, "lha")))
*p = '\0';
else if ((p = strstr(fdb.LName, "rar")))
*p = '\0';
else if ((p = strstr(fdb.LName, "tar.gz")))
*p = '\0';
else if ((p = strstr(fdb.LName, "tgz")))
*p = '\0';
else if ((p = strstr(fdb.LName, "tar.bz2")))
*p = '\0';
else if ((p = strstr(fdb.LName, "bz2")))
*p = '\0';
else if ((p = strstr(fdb.LName, "tar")))
*p = '\0';
else if ((p = strstr(fdb.LName, "arj")))
*p = '\0';
else if ((p = strstr(fdb.LName, "zip")))
*p = '\0';
else if ((p = strstr(fdb.LName, "zoo")))
*p = '\0';
else if ((p = strstr(fdb.LName, "ha")))
*p = '\0';
sprintf(p, "%s", tl(archiver.name));
Syslog('f', "%s %s", fdb.Name, fdb.LName);
fdb.Size = file_size(temp);
fdb.Crc32 = file_crc(temp, FALSE);
ut.actime = mktime(localtime(&fdb.FileDate));
ut.modtime = mktime(localtime(&fdb.FileDate));
utime(temp, &ut);
fseek(fp, - fdbhdr.recsize, SEEK_CUR);
fwrite(&fdb, fdbhdr.recsize, 1, fp);
/*
* Update symbolic link to long filename
*/
sprintf(linkpath, "%s/%s", area.Path, fdb.LName);
symlink(temp, linkpath);
free(linkpath);
} else {
break; // stop when something goes wrong
}
if (!do_quiet) {
colour(7, 0);
printf("\r");
for (i = 0; i < (strlen(temp) + 17); i++)
printf(" ");
printf("\r");
fflush(stdout);
}
}
}
fclose(fp);
free(temp);
}

8
mbfido/mbfrearc.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef _MBFREARC_H
#define _MBFREARC_H
/* $Id$ */
void ReArc(int, char *);
#endif

View File

@@ -114,17 +114,17 @@ void Help(void)
colour(CYAN, BLACK);
printf(" a adopt <area> <file> [desc] Adopt file to area\n");
printf(" c check Check filebase\n");
printf(" d delete <area> <file> Mark file in area for deletion\n");
printf(" d delete <area> <filemask> Mark file(s) in area for deletion\n");
printf(" im import <area> Import files in current dir to area\n");
printf(" in index Create filerequest index\n");
printf(" k kill Kill/move old files\n");
printf(" l list [area] List file areas or one area\n");
printf(" m move <from> <to> <file> Move file from to area\n");
printf(" p pack Pack filebase\n");
// printf(" r rearc <area> [file] [arc] Rearc file(s) in area\n");
printf(" r rearc <area> <filemask> Rearc file(s) in area to area archive type\n");
printf(" s sort <area> Sort files in a file area\n");
printf(" t toberep Show toberep database\n");
printf(" u undelete <area> <file> Mark file in area for undeletion\n");
printf(" u undelete <area> <filemask> Mark file(s) in area for undeletion\n");
colour(LIGHTBLUE, BLACK);
printf("\n Options are:\n\n");
colour(CYAN, BLACK);