From 79c89010d068b376b4b53f364055cc3841cad8e6 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Mon, 8 Mar 2004 20:51:04 +0000 Subject: [PATCH] Added mbfile rearc --- ChangeLog | 5 ++ TODO | 7 +- lib/Makefile | 10 ++- lib/mbselib.h | 16 +++- lib/rearc.c | 210 ++++++++++++++++++++++++++++++++++++++++++++++ lib/remask.c | 85 +++++++++++++++++++ mbcico/respfreq.c | 20 +---- mbfido/Makefile | 6 +- mbfido/hatch.c | 23 +---- mbfido/magic.c | 22 +---- mbfido/mbfcheck.c | 3 + mbfido/mbfdel.c | 23 ++--- mbfido/mbfile.c | 24 +++++- mbfido/mbflist.c | 20 +++-- mbfido/mbfrearc.c | 196 +++++++++++++++++++++++++++++++++++++++++++ mbfido/mbfrearc.h | 8 ++ mbfido/mbfutil.c | 6 +- mbsebbs/file.c | 22 +---- 18 files changed, 594 insertions(+), 112 deletions(-) create mode 100644 lib/rearc.c create mode 100644 lib/remask.c create mode 100644 mbfido/mbfrearc.c create mode 100644 mbfido/mbfrearc.h diff --git a/ChangeLog b/ChangeLog index 501283f9..75ee8014 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,6 +38,11 @@ v0.51.2 06-Mar-2004 Updated kill, index, check, pack, list, adopt, import, move, delete and sort to the new files database structure. The file delete function in kill didn't delete the thumbnail. + The mbfile del and undel commands accept wildcards in the + filename. + Fixed an error in check when a mangled 8.3 filename was changed + and the symbolic link was not adjusted. + Added rearc command. mbaff: When scanning for uploads, files which were hatched now have diff --git a/TODO b/TODO index e8e7702d..9bfe0d7f 100644 --- a/TODO +++ b/TODO @@ -139,10 +139,13 @@ mbfile: L: Update <-touch> - L: Rearc - L: Possibility to skip file areas from checking and reindexing. + N: The import function does not create long filenames. + + N: The import function doesn't strip the [0] from the files.bbs + when importing the description. + mbmsg: N: With the post command if a netmail area is used the netmail area will cause trouble later, should be blocked to be used on netmail diff --git a/lib/Makefile b/lib/Makefile index 311d025f..57827c2d 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -5,15 +5,15 @@ include ../Makefile.global -COMMON_SRCS = clcomm.c client.c crc.c semafore.c signame.c charset.c \ - attach.c falists.c hdr.c parsedate.c rfcmsg.c unpacker.c \ +COMMON_SRCS = clcomm.c client.c crc.c semafore.c signame.c charset.c remask.c \ + attach.c falists.c hdr.c parsedate.c rfcmsg.c unpacker.c rearc.c \ batchrd.c ftn.c pktname.c mangle.c sectest.c proglock.c \ dostran.c ftnmsg.c mbfile.c nodelock.c rawio.c strcasestr.c \ execute.c expipe.c getheader.c noderecord.c rfcaddr.c strutil.c \ faddr.c gmtoffset.c packet.c rfcdate.c term.c endian.c timers.c -COMMON_OBJS = clcomm.o client.o crc.o semafore.o signame.o charset.o \ +COMMON_OBJS = clcomm.o client.o crc.o semafore.o signame.o charset.o remask.o \ ftscprod.o attach.o falists.o hdr.o parsedate.o rfcmsg.o unpacker.o \ - batchrd.o ftn.o pktname.o mangle.o sectest.o proglock.o \ + batchrd.o ftn.o pktname.o mangle.o sectest.o proglock.o rearc.o \ dostran.o ftnmsg.o mbfile.o nodelock.o rawio.o strcasestr.o \ execute.o expipe.o getheader.o noderecord.o rfcaddr.o strutil.o \ faddr.o gmtoffset.o packet.o rfcdate.o term.o endian.o timers.o @@ -132,12 +132,14 @@ crc.o: ../config.h mbselib.h semafore.o: ../config.h mbselib.h signame.o: ../config.h mbselib.h charset.o: ../config.h mbselib.h +remask.o: ../config.h mbselib.h attach.o: ../config.h mbselib.h falists.o: ../config.h mbselib.h hdr.o: ../config.h mbselib.h parsedate.o: ../config.h mbselib.h rfcmsg.o: ../config.h mbselib.h unpacker.o: ../config.h mbselib.h +rearc.o: ../config.h mbselib.h batchrd.o: ../config.h mbselib.h ftn.o: ../config.h mbselib.h users.h mbsedb.h pktname.o: ../config.h mbselib.h diff --git a/lib/mbselib.h b/lib/mbselib.h index 7eb0b58d..7c50e7eb 100644 --- a/lib/mbselib.h +++ b/lib/mbselib.h @@ -2434,6 +2434,12 @@ int gpt_running(int); /* Is timer running */ int msleep(int); /* Milliseconds timer */ +/* + * remask.c + */ +char *re_mask(char *, int); /* Bluid file mask */ + + /************************************************************************ * @@ -2475,8 +2481,14 @@ char *charset_alias_rfc(char *); /* Search RFC alias */ int charset_set_in_out(char *, char *); /* Setup mapping */ +/* + * rearc.c + */ +int rearc(char *, char *, int); /* Rearc command */ -/************************************************************************ + + +/**************************************************************************** * * Records data */ @@ -2551,8 +2563,6 @@ struct _magic magic; struct _nodeshdr nodeshdr; /* Fidonet nodes */ struct _nodes nodes; -//struct _bill bill; /* Unsent bills */ - struct _newfileshdr newfileshdr; /* New file reports */ struct _newfiles newfiles; diff --git a/lib/rearc.c b/lib/rearc.c new file mode 100644 index 00000000..0e4357b8 --- /dev/null +++ b/lib/rearc.c @@ -0,0 +1,210 @@ +/***************************************************************************** + * + * $Id$ + * Purpose ...............: ReArc an archive. + * + ***************************************************************************** + * 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 "mbselib.h" + + +/* + * Rearchive an archive, if successfull the filename is updated. + * If it fails, return -1. + */ +int rearc(char *filename, char *arctype, int do_quiet) +{ + char *p, *uncmd = NULL, *arccmd = NULL, *unarc, *newname, *workpath, *oldpath, *temp; + int rc = 0; + + Syslog('f', "rearc(%s, %s)", filename, arctype); + + if (!do_quiet) { + colour(12, 0); + printf(" ReArc file %s", filename); + fflush(stdout); + } + + if (strchr(filename, '/') == NULL) { + if (!do_quiet) { + colour(LIGHTRED, BLACK); + printf(" no path in filename\n"); + } + Syslog('+', "rearc(%s, %s), no path in filename", filename, arctype); + return -1; + } + + if ((unarc = unpacker(filename)) == NULL) { + if (!do_quiet) { + colour(LIGHTRED, BLACK); + printf(" unknown archive type\n"); + } + return -1; + } + + if (!getarchiver(unarc)) { + if (!do_quiet) { + colour(LIGHTRED, BLACK); + printf(" no unarchiver available\n"); + } + Syslog('+', "rearc(%s, %s), no unarchiver available", filename, arctype); + return -1; + } + + uncmd = xstrcpy(archiver.funarc); + if ((uncmd == NULL) || (uncmd == "")) { + if (!do_quiet) { + colour(LIGHTRED, BLACK); + printf(" no unarchive command available\n"); + } + Syslog('+', "rearc(%s, %s), no unarchive command available", filename, arctype); + return -1; + } + + newname = calloc(PATH_MAX, sizeof(char)); + strcpy(newname, filename); + p = strrchr(newname, '.'); + *p++; + *p = '\0'; + + if (!getarchiver(arctype)) { + if (!do_quiet) { + colour(LIGHTRED, BLACK); + printf(" no archiver available\n"); + } + Syslog('+', "rearc(%s, %s), no archiver available", filename, arctype); + free(uncmd); + free(newname); + return -1; + } + + if (strcmp(unarc, archiver.name) == 0) { + if (!do_quiet) { + colour(LIGHTRED, BLACK); + printf(" already in %s format\n", arctype); + } + Syslog('+', "rearc(%s, %s), already in %s format", filename, arctype, arctype); + free(uncmd); + free(newname); + return -1; + } + + sprintf(p, "%s", archiver.name); + Syslog('f', "new filename %s", newname); + + arccmd = xstrcpy(archiver.farc); + if ((arccmd == NULL) || (arccmd == "")) { + if (!do_quiet) { + colour(LIGHTRED, BLACK); + printf(" no archive command available\n"); + } + Syslog('+', "rearc(%s, %s), no archive command available", filename, arctype); + free(uncmd); + free(newname); + return -1; + } + + /* + * unarchive and archive commands are available, create a temp directory to work in. + */ + workpath = calloc(PATH_MAX, sizeof(char)); + oldpath = calloc(PATH_MAX, sizeof(char)); + temp = calloc(PATH_MAX, sizeof(char)); + getcwd(oldpath, PATH_MAX); + sprintf(workpath, "%s/tmp/rearc%d", getenv("MBSE_ROOT"), getpid()); + sprintf(temp, "%s/%s", workpath, filename); + rc = mkdirs(temp, 0755) ? 0 : -1; + if (rc == 0) { + if ((rc = chdir(workpath)) == -1) { + WriteError("$Can't chdir to %s", workpath); + } + } + + if (!do_quiet) { + colour(11, 0); + printf("\rUnpacking file %s", filename); + fflush(stdout); + } + + /* + * Unarchive + */ + if (rc == 0) { + if ((rc = execute_str(uncmd,filename,(char *)NULL,(char*)"/dev/null",(char*)"/dev/null",(char*)"/dev/null"))) { + sync(); + sleep(1); + WriteError("Warning: unpack %s failed, trying again after sync()", filename); + if ((rc = execute_str(uncmd,filename,(char *)NULL,(char*)"/dev/null",(char*)"/dev/null",(char*)"/dev/null"))) { + WriteError("$Can't unpack %s", filename); + } + } + } + + if (!do_quiet) { + colour(10, 0); + printf("\r Packing file %s", filename); + } + + /* + * Archive + */ + if (rc == 0) { + if ((rc = execute_str(arccmd,newname,(char *)".",(char*)"/dev/null",(char*)"/dev/null",(char*)"/dev/null"))) { + sync(); + sleep(1); + WriteError("Warning: pack %s failed, trying again after sync()", newname); + if ((rc = execute_str(arccmd,newname,(char *)".",(char*)"/dev/null",(char*)"/dev/null",(char*)"/dev/null"))) { + WriteError("$Can't pack %s", newname); + } + } + } + + if (rc == 0) + unlink(filename); + + if ((rc = chdir(oldpath)) == -1) { + WriteError("$Can't chdir to %s", oldpath); + } + + /* + * Clean and remove workdir + */ + sprintf(temp, "-rf %s", workpath); + execute_pth((char *)"rm", temp, (char*)"/dev/null", (char*)"/dev/null", (char*)"/dev/null"); + if (rc == 0) + sprintf(filename, "%s", newname); + + free(workpath); + free(oldpath); + free(temp); + free(uncmd); + free(arccmd); + free(newname); + return rc; +} + + diff --git a/lib/remask.c b/lib/remask.c new file mode 100644 index 00000000..8284e9f5 --- /dev/null +++ b/lib/remask.c @@ -0,0 +1,85 @@ +/***************************************************************************** + * + * $Id$ + * Purpose ...............: Regular Expression Mask + * + ***************************************************************************** + * 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 "mbselib.h" + + +char *re_mask(char *nm, int forceupper) +{ + char *p, *q; + static char mask[256]; + + memset(&mask, 0, sizeof(mask)); + if (forceupper) + p = tl(nm); + else + p = nm; + 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: if (forceupper) + *q++ = toupper(*p); + else + *q++ = *p; + break; + } + p++; + } + *q++ = '$'; + *q++ = '\0'; + Syslog('f', "Search mask \"%s\" => \"%s\"", nm, mask); + return mask; +} + + diff --git a/mbcico/respfreq.c b/mbcico/respfreq.c index d91f3d67..d861a7a6 100644 --- a/mbcico/respfreq.c +++ b/mbcico/respfreq.c @@ -153,7 +153,7 @@ file_list *respfreq(char *nm, char *pw, char *dt) { file_list *fl = NULL; struct stat st; - char mask[256], *p, *q, *tnm, *t; + char mask[256], *p, *tnm, *t; time_t upd = 0L; int newer = 1, Send; FILE *fa, *fb, *fi; @@ -222,23 +222,7 @@ file_list *respfreq(char *nm, char *pw, char *dt) Syslog('+', "File request : %s (update (%s), password \"%s\")",MBSE_SS(nm),MBSE_SS(dt),MBSE_SS(pw)); add_report((char *)"RQ: Regular file \"%s\"",nm); - p = tl(nm); - 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; - default: *q++ = toupper(*p); break; - } - p++; - } - *q++ = '$'; - *q = '\0'; - Syslog('f', "Search mask \"%s\"", mask); + strcpy(mask, re_mask(nm, TRUE)); re_comp(mask); /* diff --git a/mbfido/Makefile b/mbfido/Makefile index df2308fc..bfbf708b 100644 --- a/mbfido/Makefile +++ b/mbfido/Makefile @@ -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 diff --git a/mbfido/hatch.c b/mbfido/hatch.c index 2f402295..298c272f 100644 --- a/mbfido/hatch.c +++ b/mbfido/hatch.c @@ -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))) { diff --git a/mbfido/magic.c b/mbfido/magic.c index cabf93fc..09dde958 100644 --- a/mbfido/magic.c +++ b/mbfido/magic.c @@ -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); diff --git a/mbfido/mbfcheck.c b/mbfido/mbfcheck.c index 13452a9d..8ad556b9 100644 --- a/mbfido/mbfcheck.c +++ b/mbfido/mbfcheck.c @@ -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++; diff --git a/mbfido/mbfdel.c b/mbfido/mbfdel.c index fa780c2b..7c4cada2 100644 --- a/mbfido/mbfdel.c +++ b/mbfido/mbfdel.c @@ -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); diff --git a/mbfido/mbfile.c b/mbfido/mbfile.c index faaf40d4..218a8869 100644 --- a/mbfido/mbfile.c +++ b/mbfido/mbfile.c @@ -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); diff --git a/mbfido/mbflist.c b/mbfido/mbflist.c index cb1cd51c..943d2441 100644 --- a/mbfido/mbflist.c +++ b/mbfido/mbflist.c @@ -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); diff --git a/mbfido/mbfrearc.c b/mbfido/mbfrearc.c new file mode 100644 index 00000000..6df406d9 --- /dev/null +++ b/mbfido/mbfrearc.c @@ -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); +} + + diff --git a/mbfido/mbfrearc.h b/mbfido/mbfrearc.h new file mode 100644 index 00000000..abbd941e --- /dev/null +++ b/mbfido/mbfrearc.h @@ -0,0 +1,8 @@ +#ifndef _MBFREARC_H +#define _MBFREARC_H + +/* $Id$ */ + +void ReArc(int, char *); + +#endif diff --git a/mbfido/mbfutil.c b/mbfido/mbfutil.c index 0dab56bf..45a24151 100644 --- a/mbfido/mbfutil.c +++ b/mbfido/mbfutil.c @@ -114,17 +114,17 @@ void Help(void) colour(CYAN, BLACK); printf(" a adopt [desc] Adopt file to area\n"); printf(" c check Check filebase\n"); - printf(" d delete Mark file in area for deletion\n"); + printf(" d delete Mark file(s) in area for deletion\n"); printf(" im import 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 Move file from to area\n"); printf(" p pack Pack filebase\n"); -// printf(" r rearc [file] [arc] Rearc file(s) in area\n"); + printf(" r rearc Rearc file(s) in area to area archive type\n"); printf(" s sort Sort files in a file area\n"); printf(" t toberep Show toberep database\n"); - printf(" u undelete Mark file in area for undeletion\n"); + printf(" u undelete Mark file(s) in area for undeletion\n"); colour(LIGHTBLUE, BLACK); printf("\n Options are:\n\n"); colour(CYAN, BLACK); diff --git a/mbsebbs/file.c b/mbsebbs/file.c index d1ca6e5f..8ac315c1 100644 --- a/mbsebbs/file.c +++ b/mbsebbs/file.c @@ -697,7 +697,7 @@ int FilenameScan() { FILE *pAreas, *pFile; int Found, Count = 0; - char *p, *q, mask[256]; + char mask[256]; char *Name; _Tag T; unsigned long OldArea; @@ -724,25 +724,7 @@ int FilenameScan() return 0; } - /* - * Make a regexp string for the users search mask. - */ - p = tl(Name); - 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; - default: *q++ = toupper(*p); break; - } - p++; - } - *q++ = '$'; - *q++ = '\0'; + strcpy(mask, re_mask(Name, TRUE)); Syslog('+', "FilenameScan(): \"%s\" -> \"%s\"", Name, mask); free(Name); re_comp(mask);